After creating the zipfile
ZipFile zipFile = new ZipFile(source);
you can scroll through each file in a zip file as follows:
ArrayList fileHeaderList = zipFile.getFileHeaders();
For each ZipFile:
for (int i = 0; i < fileHeaderList.size(); i++) { FileHeader fileHeader = (FileHeader)fileHeaderList.get(i);
Then you can get inputStream by doing this
is = zipFile.getInputStream(fileHeader);
You now have an InputStream to read.
A more detailed example of working with streams is given below (taken from the Zip4j sample package .) Although this example is still written to a file, it demonstrates the use of streams with a zip file. I suggest looking at a few examples in the examples package.
import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.List; import net.lingala.zip4j.core.ZipFile; import net.lingala.zip4j.exception.ZipException; import net.lingala.zip4j.io.ZipInputStream; import net.lingala.zip4j.model.FileHeader; import net.lingala.zip4j.unzip.UnzipUtil; public class ExtractAllFilesWithInputStreams { private final int BUFF_SIZE = 4096; public ExtractAllFilesWithInputStreams() { ZipInputStream is = null; OutputStream os = null; try {
source share