本文介绍了使用 zip4j 使用 Java 解压缩 .zip 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 net.lingala.zip4j 中的 API ZipFile 解压缩 zip 文件
I'm trying to decompress a zip file with the API ZipFile from net.lingala.zip4j
public static void unzip(File zipf, File baseDir) throws IOException, ZipException {
String source = zipf.getAbsolutePath();//"some/compressed/file.zip";
String destination = baseDir.getPath();//"some/destination/folder";
// String password = "password";
try {
ZipFile zipFile = new ZipFile(source);
if (zipFile.isEncrypted()) {
// zipFile.setPassword(password);
}
zipFile.extractAll(destination);
} catch (ZipException e) {
e.printStackTrace();
}
}
我总是收到错误:
net.lingala.zip4j.exception.ZipException: 可能不是 zip 文件或损坏的 zip 文件
是否有其他解决方案可以正确解压缩 file.zip?
May there is other solution to unZip the file.zip correctly?
推荐答案
你的代码很完美.我已经在我的系统上运行了你的代码,它运行良好.我使用了 .请使用不同的 zip 文件再次运行它.您的 zip 文件可能已损坏.
Your code is perfect. I have run your code on my system, it works superbly. I have used zip4j-1.3.1.jar
from http://central.maven.org/maven2/net/lingala/zip4j/zip4j/1.3.1/zip4j-1.3.1.jar. Please run it again with a different zip file. Your zip file may be a corrupted one.
这篇关于使用 zip4j 使用 Java 解压缩 .zip 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!