/**
* 解压缩zip文件
*
* [@param](https://my.oschina.net/u/2303379) dir 下载的zip所在文件夹路径
* [@param](https://my.oschina.net/u/2303379) filePath zip文件路径
* [@param](https://my.oschina.net/u/2303379) fileName zip的文件名,uuid
* [@return](https://my.oschina.net/u/556800) 解压成功:true,解压失败:false
*/
public boolean unZip(String dir, String filePath, String fileName) {
boolean isSuccessful = true;
try {
//创建解压路径
File unzipPath = new File(dir + "/" + fileName + "/");
if (!unzipPath.exists()) {
unzipPath.mkdir();
}
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(filePath));
ZipInputStream zis = new ZipInputStream(bis);
BufferedOutputStream bos = null;
//byte[] b = new byte[1024];
ZipEntry entry = null;
while ((entry = zis.getNextEntry()) != null) {
String entryName = entry.getName();
//若解压出来的是文件夹,则创建
if (entry.isDirectory()) {
File entryDir = new File(unzipPath + "/" + entryName);
if (!entryDir.exists()) {
entryDir.mkdir();
}
} else {//若解压出来的是文件,则写出
bos = new BufferedOutputStream(new FileOutputStream(unzipPath + "/" + entryName));
int b = 0;
while ((b = zis.read()) != -1) {
bos.write(b);
}
bos.flush();
bos.close();
}
}
zis.close();
} catch (IOException e) {
isSuccessful = false;
}
return isSuccessful;
}
转载于:https://my.oschina.net/OriginLeon/blog/858437