Java IO Tutorial - Java ZipFile(String name) Constructor








Syntax

ZipFile(String name) constructor from ZipFile has the following syntax.

public ZipFile(String name)  throws IOException

Example

In the following code shows how to use ZipFile.ZipFile(String name) constructor.

import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/*from w w  w.j ava 2 s .  c o m*/
public class Main {

  public static void main(String[] args) throws Exception {
    ZipFile zipFile = new ZipFile("testfile.zip");

    Enumeration zipEntries = zipFile.entries();

    while (zipEntries.hasMoreElements()) {
      System.out.println(((ZipEntry) zipEntries.nextElement()).getName());
    }
  }
}