Decompress .zip file with Java using zip4j

2019-06-07 05:03发布

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?

标签: java zip zip4j
1条回答
闹够了就滚
2楼-- · 2019-06-07 05:28

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.

查看更多
登录 后发表回答