如何使用 zip4j 提取具有密码保护的 zip 文件

How to use zip4j to extract an zip file with password protection(如何使用 zip4j 提取具有密码保护的 zip 文件)

本文介绍了如何使用 zip4j 提取具有密码保护的 zip 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解压缩带有密码保护的 zip 文件.我知道有一个名为zip4j"的 java 库可以帮助我.但是我无法打开 zip4j 网站来查看教程.

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.

我已经用另一个镜像下载了 zip4j 库,但我不知道如何使用它.有没有人可以粘贴使用 zip4j 解压缩密码保护 zip 文件的示例代码?

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 网站

非常感谢!

推荐答案

尝试以下操作并确保您使用的是最新的 Zip4j 库 (1.3.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();
}

这篇关于如何使用 zip4j 提取具有密码保护的 zip 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何使用 zip4j 提取具有密码保护的 zip 文件

基础教程推荐