如何在Java中使用truezip在tar中从jar中列出文件()?
我试图列出tar中的所有文件,包括jar中的文件 如何在Java或其他api中使用truezip实现这一点如何在Java中使用truezip在tar中从jar中列出文件()?,java,jar,tar,truezip,Java,Jar,Tar,Truezip,我试图列出tar中的所有文件,包括jar中的文件 如何在Java或其他api中使用truezip实现这一点 谢谢在stackoverflow中找到了类似的线程 希望上面的链接有帮助 这将列出jar中的文件。 您可以使用JarFile和JarEntry的组合来获取列表 JarFile randomJar = new JarFile("randomname.jar"); Enumeration enumEntries = randomJar.entries(); while (enumEntrie
谢谢在stackoverflow中找到了类似的线程 希望上面的链接有帮助 这将列出jar中的文件。 您可以使用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 );
}
在stackoverflow中发现了类似的线程 希望上面的链接有帮助 这将列出jar中的文件。 您可以使用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 );
}
使用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
}
使用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
}
您好,谢谢您的回复,我想这有点不同,我在一个tar下列出了文件。我发现另一个线程也在问同样的问题。看起来他们有一些答案:嗨,谢谢你的回复,我想这有点不同,我在一个tar下列出了文件,发现另一个线程问了同样的问题。看起来他们有一些答案: