import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ZipUtil; import java.io.File; import java.nio.charset.Charset; public class RecursiveUnzip { final static File destDir = new File("D:\\python\\newProject\\excel"); public static void main(String[] args) { String zipFilePath = "D:\\python\\newProject\\excel\\1009重置.zip";
unzip(new File(zipFilePath), Charset.forName("GBK") ); } public static void unzip(File zipFilePath, Charset charset) { if (zipFilePath.isDirectory()) { //如果是文件夹,则递归遍历 for (File loopFile : FileUtil.loopFiles(zipFilePath)) { unzip(loopFile, charset); } } else { //如果是文件,则直接解压 if (zipFilePath.exists() && zipFilePath.getName().contains("zip")) { File unzip = ZipUtil.unzip(zipFilePath, charset); unzip(unzip, charset); } else if (zipFilePath.getName().contains("xlsx")) { //将所有XLSX 移动至根目录 FileUtil.move(zipFilePath, destDir, false); } } } }
标签:解压,unzip,Java,zipFilePath,charset,Hutool,File,import,Charset From: https://www.cnblogs.com/AngelHaxi/p/17751957.html