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

前端 未结 2 998
醉话见心
醉话见心 2020-12-31 09:45

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

2条回答
  •  滥情空心
    2020-12-31 10:15

    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();
    }
    

提交回复
热议问题