Decompress .zip file with Java using zip4j

情到浓时终转凉″ 提交于 2019-12-23 03:12:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!