Java ZipFile get InputStream for ZipEntry

Description

Java ZipFile get InputStream for ZipEntry

import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

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

    Enumeration<? extends ZipEntry> e = zf.entries();
    ZipEntry entry = null;/*ww  w.  j  ava  2 s.  c  o  m*/

    while (e.hasMoreElements()) {
      entry = e.nextElement();

      InputStream is = zf.getInputStream(entry);

      /* Read data for the entry using the is object */

      System.out.println(entry.getName());
      is.close();
    }
    zf.close();
  }
}



PreviousNext

Related