package Jzip;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
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 JZip {
public static void jzip(String f){
File file =new File(f);
ZipInputStream zin;
try {
System.out.println("解压中。。。");
ZipFile zipfile=new ZipFile(file);
zin=new ZipInputStream(new FileInputStream(file));
ZipEntry entry=zin.getNextEntry();
while((entry=zin.getNextEntry())!=null &&
!entry.isDirectory()){
File tmp =new File("C:/"+entry.getName());
if(!tmp.exists()){
tmp.getParentFile().mkdirs();
OutputStream os=new FileOutputStream(tmp);
InputStream in=zipfile.getInputStream(entry);
int count=0;
while((count = in.read())!= -1){
os.write(count);
}
os.close();
in.close();
}
zin.closeEntry();
System.out.println(entry.getName()+"解压成功");
}
zin.close();
zipfile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
jzip("D:\\Test.zip");
}
}
文件无法完成解压,我有个zip文件,解压只解压了一部分,附图,望各位老师认真看看代码