庄生晓梦

庄生晓梦迷蝴蝶

博客园 首页 新随笔 联系 订阅 管理
File outFileDir = new File(outDir);
if (!outFileDir.exists()) {
boolean isMakDir = outFileDir.mkdirs();
if (isMakDir) {
log.info("创建压缩目录成功");
}
}
ZipFile zip = new ZipFile(zipFile, "gbk");
for (Enumeration enumeration = zip.getEntries(); enumeration.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) enumeration.nextElement();
String zipEntryName = entry.getName();
InputStream in = zip.getInputStream(entry);

if (entry.isDirectory()) { //处理压缩文件包含文件夹的情况
File fileDir = new File(outDir + zipEntryName);
fileDir.mkdir();
continue;
}

File file = new File(outDir, zipEntryName);
file.createNewFile();
OutputStream out = new FileOutputStream(file);
byte[] buff = new byte[1024];
int len;
while ((len = in.read(buff)) > 0) {
out.write(buff, 0, len);
}
in.close();
out.close();
}
posted on 2019-06-18 22:41  qwop  阅读(3500)  评论(0编辑  收藏  举报