Как сделать listfiles () из jar в tar с помощью truezip в Java? - PullRequest
1 голос
/ 22 марта 2011

Я пытаюсь перечислить все файлы в tar, включая файлы в jar.

Как я могу сделать это, используя truezip в Java или других API?

Спасибо

Ответы [ 2 ]

5 голосов
/ 01 мая 2011

Используя TrueZIP 7, вы можете использовать что-то вроде этого:

public static void main(String args[]) throws IOException {
    // Remember to set to add the following dependencies to the class path:
    // Compile time artifactId(s): truezip-file
    // Run time artifactId(s): truezip-kernel, truezip-driver-file, truezip-driver-tar, truezip-driver-zip
    TFile.setDefaultArchiveDetector(new TDefaultArchiveDetector("tar|zip"));
    search(new TFile(args[0])); // e.g. "my.tar" or "my.zip"
    TFile.umount(); // commit changes
}

private void search(TFile entry) throws IOException {
    if (entry.isDirectory()) {
        for (TFile member : dir.listFiles())
            search(member);
    } else if (entry.isFile()) {
        // [do something with entry]
    } // else is special file or non-existent
}
0 голосов
/ 23 марта 2011

Нашел похожую тему здесь в stackoverflow Как извлечь файл tar в Java?

Надеюсь, что приведенная выше ссылка поможет.

Это приведет к выводу списка файлов вбаночка.Вы можете использовать комбинацию JarFile и JarEntry для получения списка.

JarFile randomJar = new JarFile("randomname.jar");
Enumeration enumEntries = randomJar.entries();
while (enumEntries.hasMoreElements()) {
    JarEntry jarEntry = (JarEntry)enumEntries.nextElement();
    String name = jarEntry.getName();
    System.out.println("Name = " + name );
}

http://download.oracle.com/javase/1.4.2/docs/api/java/util/jar/JarFile.html http://download.oracle.com/javase/1.4.2/docs/api/java/util/zip/ZipEntry.html

...