How to Compress/Decompress tar.gz files in java

前端 未结 7 1106
粉色の甜心
粉色の甜心 2020-12-02 17:05

Can anyone show me the correct way to compress and decompress tar.gzip files in java i\'ve been searching but the most i can find is either zip or gzip(alone).

7条回答
  •  爱一瞬间的悲伤
    2020-12-02 17:21

    I've written a wrapper for commons-compress called jarchivelib that makes it easy to extract or compress from and into File objects.

    Example code would look like this:

    File archive = new File("/home/thrau/archive.tar.gz");
    File destination = new File("/home/thrau/archive/");
    
    Archiver archiver = ArchiverFactory.createArchiver("tar", "gz");
    archiver.extract(archive, destination);
    

提交回复
热议问题