问题
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();
}
}
I always got the error:
net.lingala.zip4j.exception.ZipException: Probably not a zip file or a corrupted zip file
May there is other solution to unZip the file.zip correctly?
回答1:
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.
来源:https://stackoverflow.com/questions/37564863/decompress-zip-file-with-java-using-zip4j