package com.javatest.techzero.gui;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
public class ZipFileDemo {
@SuppressWarnings("resource")
public static void main(String args[]) throws Exception {
File file = new File("d:" + File.separator + "test.zip");
File outFile = null;
ZipFile zipFile = new ZipFile(file);
ZipInputStream zipInput = new ZipInputStream(new FileInputStream(file));
ZipEntry entry = null;
InputStream input = null;
OutputStream out = null;
while ((entry = zipInput.getNextEntry()) != null) {
System.out.println("开始解压缩" + entry.getName() + "文件。。。");
outFile = new File("d:" + File.separator + entry.getName());
if (!outFile.getParentFile().exists()) {
outFile.getParentFile().mkdir();
}
if (!outFile.exists()) {
outFile.createNewFile();
}
input = zipFile.getInputStream(entry);
out = new FileOutputStream(outFile);
int temp = 0;
while ((temp = input.read()) != -1) {
//System.out.println(temp);
out.write(temp);
}
input.close();
out.close();
}
System.out.println("Done!");
}
}