How to list contents of compressed tar file in Java

How can I list the contents of a compressed tar file in Java without extracting the files? I looked at apache ant api and I see how to extract files, but I cannot figure out how to simply list them. The tar files are either bz2 or gz.

+3
source share
2 answers

I recommend using TrueZIP . This is really good.

TrueZIP is a platform for virtual file systems and a library for accessing archive files, as if they were just old directories.

As a platform, TrueZIP provides interfaces and classes for writing file system drivers that connect to the volume of an integrated file system.

TrueZIP / , .

, . TAR, *.tar.gz *.tar.bz2 . JavaDocs , , - JavaDoc, .

... , : , TrueZIP. , "", .

+4
TarArchiveInputStream tin = new TarArchiveInputStream(new FileInputStream(tempFile));
ArchiveEntry entry = tin.getNextEntry();
while (entry != null) {
  System.out.println("File Name " + entry.getName());//List file name      
}
0

All Articles