您的位置:首页 > 编程语言 > Java开发

java解压zip文件的代码

2011-12-01 20:47 417 查看
[b]java解压zip文件的代码[/b]

/**
* 解压zip格式的压缩包
*
* @param filePath
* 压缩文件路径
* @param outPath
* 输出路径
* @return 解压成功或失败标志
*/
public static Boolean unZip(String filePath, String outPath) {
String unzipfile = inPath; // 解压缩的文件名
try {
ZipInputStream zin = new ZipInputStream(new FileInputStream(
unzipfile));
ZipEntry entry;
// 创建文件夹
while ((entry = zin.getNextEntry()) != null) {
if (entry.isDirectory()) {
File directory = new File(outPath, entry.getName());
if (!directory.exists()) {
if (!directory.mkdirs()) {
System.exit(0);
}
}
zin.closeEntry();
} else {
File myFile = new File(entry.getName());
FileOutputStream fout = new FileOutputStream(outPath
+ myFile.getPath());
DataOutputStream dout = new DataOutputStream(fout);
byte[] b = new byte[1024];
int len = 0;
while ((len = zin.read(b)) != -1) {
dout.write(b, 0, len);
}
dout.close();
fout.close();
zin.closeEntry();
}
}
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: