/**
*
* inputFile 压缩包文件的路径 destDirPath 解压到哪个目录 filename 设置解压之后的文件名
*/
public static void zipUncompress(String inputFile, String destDirPath, String filename) throws Exception {
try {
File srcFile = new File(inputFile);//获取当前压缩文件
// 判断源文件是否存在
if (!srcFile.exists()) {
throw new Exception(srcFile.getPath() + "所指文件不存在");
}
ZipFile zipFile = new ZipFile(srcFile);//创建压缩文件对象
//开始解压
Enumeration<?> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
// 如果是文件夹,就创建个文件夹
if (entry.isDirectory()) {
String dirPath = destDirPath + "/" + entry.getName();
srcFile.mkdirs();
} else {
// 如果是文件,就先创建一个文件,然后用io流把内容copy过去
File targetFile = new File
Java实现解压压缩包
最新推荐文章于 2024-08-01 15:05:06 发布