Wayne Wayne - 4 months ago 22
Java Question

How to list the contents of a compressed tar file in Java

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

Answer

I recommend using TrueZIP. It's really good.

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

As a framework, TrueZIP provides the interfaces and classes to write file system drivers which plug-in to its federated file system space.

As a library, TrueZIP provides convenient multi-threaded read/write access to archive files as if they were just plain old directories in a file system path.

It's an excellent, fast library. It has TAR drivers, and can handle *.tar.gz and *.tar.bz2 files. The JavaDocs are clear and complete, though I found the standalone tutorials insufficient - I had to read the JavaDoc to get things working.

...Which brings me to the only downside I found: it might take a little while to wrap your head around TrueZIP. Initially, I had issues getting anything to work, but it "clicked" after a little while and I had no more difficulties.