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

假装没事ソ 提交于 2019-12-05 12:26:12

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.

TarArchiveInputStream tin = new TarArchiveInputStream(new FileInputStream(tempFile));
ArchiveEntry entry = tin.getNextEntry();
while (entry != null) {
  System.out.println("File Name " + entry.getName());//List file name      
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!