public static void decompress(String srcPath, String dest) throws Exception {
File file = new File(srcPath);
if (!file.exists()) {
throw new RuntimeException(srcPath + "所指文件不存在");
}
ZipFile zf = new ZipFile(file);
Enumeration entries = zf.entries();
ZipEntry entry = null;
while (entries.hasMoreElements()) {
entry = (ZipEntry) entries.nextElement();
System.out.println("解压" + entry.getName());
if (entry.isDirectory()) {
String dirPath = dest + File.separator + entry.getName();
File dir = new File(dirPath);
dir.mkdirs();
} else {
// 表示文件
File f = new File(dest + File.separator + entry.getName());
if (!f.exists()) {
String dirs = f.getParent();
File parentDir = new File(dirs);
parentDir.mkdirs();
}
f.createNewFile();
// 将压缩文件内容写入到这个文件中
InputStream is = zf.getInputStream(entry);
FileOutputStream fos = new FileOutputStream(f);
int count;
byte[] buf = new byte[8192];
while ((count = is.read(buf)) != -1) {
fos.write(buf, 0, count);
}
is.close();
fos.close();
}
}
}
解压zip
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 项目需求是本地下载.zip的HTTP链接,解压后保存在沙盒,然后用Webview展示HTML,找了下第三方解压缩的...
- 项目中,因为随时需要更新数据包(不可能发布一等到发布下一个版本),好比我自己的项目中,就包含了,HTML和一些资源...
- Dot Net下解压一个文件很简单: 但是一个程序在Mac下运行Dot Net程序去解压一个zip文件,目录结构都...