| 
 
TA的每日心情|  | 衰 前天 08:58
 | 
|---|
 签到天数: 1021 天 [LV.10]以坛为家III | 
 
| 复制代码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();
        }
    }
 | 
 评分
1
查看全部评分
 |