0

こんにちは、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();
    }

誰か助けてくれませんか?

ありがとう。

4

1 に答える 1

1

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.

于 2013-03-20T12:12:42.370 に答える