Java ZipFile get ZipEntry via stream

Description

Java ZipFile get ZipEntry via stream

import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Stream;
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");

    Stream<? extends ZipEntry> entryStream = zf.stream();
    entryStream.forEach(entry -> {/*from ww  w  .j  a v  a 2  s.  c om*/
      try {
        // Get the input stream for the current zip entry
        InputStream is = zf.getInputStream(entry);
        //deal with is
        
        is.close();
        System.out.println(entry.getName());
      } catch (IOException e) {
        e.printStackTrace();
      }

    });
    zf.close();
  }
}



PreviousNext

Related