如何使用 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();
}
相关文章