分享文件解压的源码作为参考:
修改文件路径即可使用下面代码,
public static void zipGetIcon() throws IOException{
// TODO Auto-generated method stub
ZipInputStream zis = new ZipInputStream(new FileInputStream("D:\\a.zip"));
ZipEntry entry = null;
ZipFile file = new ZipFile("D:\\a.zip");
int ch = -1;
byte[] buf = new byte[8 * 1024];
while((entry = zis.getNextEntry()) != null){
System.out.println(entry);
File outFile = new File("D:\\kingfo_zhou\\" + entry.getName() + ".jpg");
if(!outFile.getParentFile().exists()){
outFile.getParentFile().mkdirs();
}
if(!outFile.exists()){
outFile.createNewFile();
}
FileOutputStream out = new FileOutputStream(outFile);
InputStream is = file.getInputStream(entry);
while((ch = is.read(buf)) != -1){
out.write(buf, 0, ch);
out.flush();
}
out.close();
}
zis.close();
file.close();
System.out.println();
}
可以修改这个方法,路径对外开发等,或者命名规则按照用户自定义也可以。