Loading... ``` 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[1024]; int len; while ((len = zis.read(buffer)) != -1) { fos.write(buffer, 0, len); } } } zis.closeEntry(); } System.out.println("解压完成!"); } catch (IOException e) { e.printStackTrace(); } } ``` Last modification:September 22, 2025 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 0 如果觉得我的文章对你有用,请随意赞赏