How to use zip4j to extract an zip file with password protection

强颜欢笑 提交于 2019-11-29 12:25:52

问题


I am trying to unzip a zipfile with password protection. I know there is a java library named "zip4j" that could help me. But I am failing to open the zip4j website to see the tutorial.

I had download zip4j library with another mirror but I don't know how to use it. Is there anyone that could paste example code for using zip4j unzip password protection zip file?

zip4j website

thanks so much!


回答1:


Try the following and make sure you are using the most recent Zip4j library (1.3.1):

String source = "folder/source.zip";
String destination = "folder/source/";
String password = "password";

try {
    ZipFile zipFile = new ZipFile(source);
    if (zipFile.isEncrypted()) {
        zipFile.setPassword(password);
    }
    zipFile.extractAll(destination);
} catch (ZipException e) {
    e.printStackTrace();
}


来源:https://stackoverflow.com/questions/11174851/how-to-use-zip4j-to-extract-an-zip-file-with-password-protection

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