我对Java很新,我试图使用java提取受密码保护的ZIP文件,并且我已经编写了代码同样,但我得到了几个方法,如isEncrypted(),fileHeaderList(),extractFile(), 错误我搜索了几个相关的帖子/问题,但没有找到确切的解决方案。 你们谁能帮助我在这个问题上我想使用zip4j jar文件提取受密码保护的ZIP文件,但我得到以下错误
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();
}
}
你会得到什么错误? –
嗨Riaan,我编辑了我在代码中给出错误信息的帖子。 –