zip 包解压缩
ZipInputStream zipInput = new ZipInputStream(inputStream, Charset.forName("GBK"));
//读取一个目录
ZipEntry nextEntry = zipInput.getNextEntry();
String outPath = appConfig.getTmpPath() + System.currentTimeMillis() + File.separator;
File outFile = new File(outPath);
if (!outFile.exists()) {
outFile.mkdirs();
}
//不为空进入循环
while (nextEntry != null) {
String name = nextEntry.getName();
File file = new File(outPath + File.separator + name);
fileProber(file);
//如果是目录,创建目录
if (name.endsWith("/")) {
file.mkdirs();
} else {
file.createNewFile();
//文件则写入具体的路径中
FileOutputStream fileOutputStream = new FileOutputStream(file);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
int n;
byte[] bytes = new byte[1024];
while ((n = zipInput.read(bytes)) != -1) {
bufferedOutputStream.write(bytes, 0, n);
}
//关闭流
bufferedOutputStream.close();
fileOutputStream.close();
}
//关闭当前
zipInput.closeEntry();
//读取下一个目录,作为循环条件
nextEntry = zipInput.getNextEntry();
}
public static void fileProber(File dirFile) throws Exception {
File parentFile = dirFile.getParentFile();
if (!parentFile.exists()) {
fileProber(parentFile);
parentFile.mkdirs();
}
}