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.