前面,笔者讲到。如何把文件打包为zip包,那么反过来怎么把zip文件包解压为正常文件呢?把zip包解压为正常文件包,要比把文件打包为zip简单一点。因为存在多级文件的压缩,却不存在多级文件的解压缩。也就是说,压缩时,你要把所有文件都塞到压缩包里。而解压缩只需要解压一级,压缩包里面的压缩文件则不必理会。
直接上代码喽:
/**
* 解压文件
* @param zipPath 要解压的目标文件
* @param descDir 指定解压目录
* @return 解压结果:成功,失败
*/
@SuppressWarnings("rawtypes")
public boolean decompressZip(String zipPath, String descDir) {
File zipFile = new File(zipPath);
boolean flag = false;
File pathFile = new File(descDir);
if(!pathFile.exists()){
pathFile.mkdirs();
}
ZipFile zip = null;
try {
zip = new ZipFile(zipFile, Charset.forName("gbk"));//防止中文目录,乱码
for(Enumeration entries = zip.entries(); entries.hasMoreElements();