TrueZip - How to decompress inner jar/zip files without expanding them as directories?

十年热恋 提交于 2019-12-13 12:11:25

问题


I'm creating a tzp file using TrueZip 7, and the cp_rp method to add all directory contents at once to the tzp file.

After that, I'm trying to extract all contents of the tzp file to a target directory. However, the call:

zipFile = new TFile("test.zip");
public void extract(TFile file){
  for (TFile iFile : zipFile.listFiles()){
    if(iFile.isDirectory()){
       extract(iFile);
    }else{
       File output = new File(iFile.getPath());
       iFile.mv(output);
    }
  }
}

Fails with an error: java.io.IOException: [path]\test.zip\Myjar.jar (destination exists already). If I use cp instead of mv, then the error is [path]\test.zip\Myjar.jar (contained in [path]\test.zip\Myjar.jar)

The problem also seems to be that TrueZip identifies zips and jars as both directories and archives, so when doing a isDirectory() on them, this succeeds, and doing a listFiles() returns all files contained within, so running a cp() on files recursively causes all jar/zip contents to be copied as directories.

What is the correct way of extracting these archive files without expanding them?


回答1:


Extracting an archive file to a directory can be done with one method call:

TFile archive = new TFile("archive.zip");
TFile directory = new TFile("directory");
TFile.cp_rp(archive, directory, TArchiveDetector.NULL, TArchiveDetector.NULL);

The trick is to use TArchiveDetector.NULL when traversing the directory trees.



来源:https://stackoverflow.com/questions/6393090/truezip-how-to-decompress-inner-jar-zip-files-without-expanding-them-as-direct

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!