嗨,我正在尝试使用 TrueZIP 解压缩文件,但这样做时出现异常
de.schlichtherle.truezip.fs.archive.FsReadOnlyArchiveFileSystemException: This is a read-only archive file system!
它适用于某些文件并为其他文件抛出异常。
所以我尝试更改权限并使其可写,但这也不起作用。
这是我的代码:
public void unzipFiles(TFile[] files){
try{
for(int i=0; i < files.length; i++){
System.out.println("Processing please wait ...");
if(files[i].isArchive()){
if(files[i].getName().endsWith(".zip")){
System.out.println(files[i].getName());
System.out.println("Is writable "+files[i].canWrite());
//change the file permission to be writable
if(files[i].canWrite() == false){
files[i].setWritable(true);
files[i].setExecutable(true);
System.out.println("After setting it writeable "+files[i].canWrite());
}
String filename = files[i].getName();
String pathToExtract = files[i].getParent() + "\\" + filename.substring(0, filename.lastIndexOf("."));
File createdirectory = new File(pathToExtract);
TFile directoryToExtract = new TFile(pathToExtract);
TFile.cp_rp(files[i], directoryToExtract, TArchiveDetector.NULL, TArchiveDetector.NULL);
System.out.println("Unzipping files ..");
TFile.rm_r(files[i]);
System.out.println("Deleting Zip file..");
numOfZips = numOfZips + 1;
unzipFiles(directoryToExtract.listFiles());
}
}else{
if(files[i].isDirectory()){
unzipFiles(files[i].listFiles());
}
}
}
}catch(Exception e){
e.printStackTrace();
}
有人可以帮忙吗?
谢谢。