我对 Java 很陌生,我正在尝试使用 java 提取受密码保护的 ZIP 文件,并且我已经编写了相同的代码,但是对于一些方法,例如 isEncrypted()、fileHeaderList()、extractFile(),我遇到了错误,我搜索了一些相关的帖子/问题,但没有找到确切的解决方案。你们中的任何人都可以在这个问题上帮助我吗
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipFile;
import net.lingala.zip4j.model.FileHeader;
public class Extraction {
public Extraction() {
try {
ZipFile zipFile = new ZipFile("C:\\Users\\rajesh\\Desktop\\ZipFile\\file1.zip");
//Error for isEncrypted() "The method isEncrypted() is undefined for the type ZipFile"
if (zipFile.isEncrypted()) {
zipFile.setPassword("MYPASS!");
}
//The method getFileHeaders() is undefined for the type ZipFile
List fileHeaderList = zipFile.getFileHeaders();
for (int i = 0; i < fileHeaderList.size(); i++) {
FileHeader fileHeader = (FileHeader)fileHeaderList.get(i);
//The method extractFile(FileHeader, String) is undefined for the type ZipFile
zipFile.extractFile(fileHeader, "C:\\Users\\rajesh\\Desktop\\ZipFile");
}
} catch (Exception e) {
System.out.println("Please Try Again");
}
}
public static void main(String[] args) {
new Extraction();
}
}