This example reads a ZIP file and decompresses the first entry.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class Main {
public static void main(String[] argv) throws Exception {
String inFilename = "infile.zip";
ZipInputStream in = new ZipInputStream(new FileInputStream(inFilename));
ZipEntry entry = in.getNextEntry();
String outFilename = "o";
OutputStream out = new FileOutputStream(outFilename);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
in.close();
}
}
|