Java解压zip压缩包
public static void unzip(String zipFilePath, String destDirPath) {File destDir = new File(destDirPath);
if (!destDir.exists()) {
destDir.mkdirs();
}
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFilePath), Charset.forName("GBK"))) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
String filePath = destDirPath + File.separator + entry.getName();
if (entry.isDirectory()) {
// 如果是目录,创建目录
new File(filePath).mkdirs();
} else {
// 如果是文件,创建父目录并写入文件
File parent = new File(filePath).getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
try (FileOutputStream fos = new FileOutputStream(filePath)) {
byte[] buffer = new byte;
int len;
while ((len = zis.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
}
}
zis.closeEntry();
}
System.out.println("解压完成!");
} catch (IOException e) {
e.printStackTrace();
}
} 谢谢分享 谢谢分享,已回复
页:
[1]