如何在java中压缩/解压缩tar.gz文件 [英] How to Compress/Decompress tar.gz files in java
本文介绍了如何在java中压缩/解压缩tar.gz文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以告诉我正确的方式来压缩和解压缩tar.gzip文件在我一直在搜索,但我最大的可以找到是zip或gzip(单独)。
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).
推荐答案
我最喜欢的是plexus-archiver - 请参阅 GitHub 。
My favorite is plexus-archiver - see sources on GitHub.
另一个选择是Apache - 压缩 - (请参见 mvnrepository )。
Another option is Apache commons-compress - (see mvnrepository).
使用plexus-utils,unarchive的代码如下:
With plexus-utils, the code for unarchiving looks like this:
final TarGZipUnArchiver ua = new TarGZipUnArchiver();
ua.setSourceFile(sourceFile);
destDir.mkdirs();
ua.setDestDirectory(destDir);
ua.extract();
类似* Archiver类存档。
Similar *Archiver classes are there for archiving.
使用Maven,您可以使用此依赖关系:
With Maven, you can use this dependency:
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>2.2</version>
</dependency>
这篇关于如何在java中压缩/解压缩tar.gz文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文