Reputation: 1
Hi I am trying to unzip files using TrueZIP and while doing so I get an exception
de.schlichtherle.truezip.fs.archive.FsReadOnlyArchiveFileSystemException: This is a read-only archive file system!
It works for some files and throws exception for others.
So I tried changing the permission and making it writable but that doesn't work either.
Here is my code:
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();
}
Can someone help please?
Thanks.
Upvotes: 0
Views: 181
Reputation: 3155
Note that TrueZIP does not support permissions. So setWritable
and setExecutable
are about the only methods which do not get overridden to have a meaning in an archive file. If you had checked their boolean return value, you would have recognized that they return false
if the file object is addressing an entry within an archive file.
Apart from this, I don't see where you would modify an archive file and so I can't comment how you get an FsReadOnlyArchiveFileSystemException
. It's generally thrown if you try to modify a read-only archive file system, i.e. if the archive file is read-only.
If you provide a stack trace, then it may become obvious why this happened.
Upvotes: 1