任何人都可以向我展示在我一直在搜索的Java中压缩和解压缩tar.gzip文件的正确方法,但是我能找到的最多是zip或gzip(单独)。
我最喜欢的是plexus-archiver-请参阅GitHub上的资源。
另一个选项是Apache commons-compress-(请参阅mvnrepository)。
使用plexus-utils,用于取消存档的代码如下所示:
final TarGZipUnArchiver ua = new TarGZipUnArchiver();
// Logging - as @Akom noted, logging is mandatory in newer versions, so you can use a code like this to configure it:
ConsoleLoggerManager manager = new ConsoleLoggerManager();
manager.initialize();
ua.enableLogging(manager.getLoggerForComponent("bla"));
// -- end of logging part
ua.setSourceFile(sourceFile);
destDir.mkdirs();
ua.setDestDirectory(destDir);
ua.extract();
有类似的* Archver类可以存档。
使用Maven,您可以使用以下依赖关系:
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>2.2</version>
</dependency>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句