如何通过使用Java中的truezip从tar中的jar中列出文件()? [英] How to listfiles() from jar in a tar by using truezip in Java?

查看:164
本文介绍了如何通过使用Java中的truezip从tar中的jar中列出文件()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试列出tar中的所有文件,包括jar中的文件.

I am trying to list all files in a tar, including files in jar.

如何通过在Java或其他api中使用truezip来做到这一点?

How can I do this by using truezip in Java or other api?

谢谢

推荐答案

使用TrueZIP 7,您可以使用以下代码:

Using TrueZIP 7, you could use something like this:

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
}

这篇关于如何通过使用Java中的truezip从tar中的jar中列出文件()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆