/**
* 解压文件到指定目录
* @param zipFile
* @param descDir
* @author sqdll
*/
@SuppressWarnings("rawtypes")
public static void unZipFiles(File zipFile,String descDir)throws IOException {
File pathFile = new File(descDir);
if (!pathFile.exists()) {
pathFile.mkdirs();
}
//相关变量
ZipEntry entry = null;
InputStream in = null;
OutputStream out = null;
String outPath = null;
File file = null;
ZipFile zip = new ZipFile(zipFile, Charset.forName("GBK")); //待解压文件
for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) {
entry = (ZipEntry) entries.nextElement();
in = zip.getInputStream(entry);
outPath = (descDir + entry.getName()).replaceAll("\\*", "/");
//判断路径是否存在,不存在则创建文件路径
file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
if (!file.exists()) {
file.mkdirs();
}
//判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
if (new File(outPath).isDirectory()) {
continue;
}
//输出文件路径信息
System.out.println(outPath);
out = new FileOutputStream(outPath);
byte[] buf1 = new byte[1024];
int len;
while ((len = in.read(buf1)) > 0) {
out.write(buf1, 0, len);
}
in.close();
out.close();
}
System.out.println("******************解压完毕********************");
}