解压缩 BZIP2 档案 [英] Uncompress BZIP2 archive
本文介绍了解压缩 BZIP2 档案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以解压缩 zip、gzip 和 rar 文件,但我还需要解压缩 bzip2 文件以及解压缩它们 (.tar).我还没有找到一个好的库来使用.
我使用 Java 和 Maven 非常理想,我想将它作为依赖项包含在 POM 中.
您推荐哪些图书馆?
解决方案
我能看到的最佳选择是 Apache Commons使用此 Maven 依赖项压缩.
<依赖><groupId>org.apache.commons</groupId><artifactId>commons-compress</artifactId><version>1.0</version></依赖>
来自示例:
<块引用>FileInputStream in = new FileInputStream("archive.tar.bz2");FileOutputStream out = new FileOutputStream("archive.tar");BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in);最终字节[]缓冲区=新字节[缓冲区大小];整数 n = 0;while (-1 != (n = bzIn.read(buffer))) {out.write(buffer, 0, n);}关闭();bzIn.close();
I can uncompress zip, gzip, and rar files, but I also need to uncompress bzip2 files as well as unarchive them (.tar). I haven't come across a good library to use.
I am using Java along with Maven so ideally, I'd like to include it as a dependency in the POM.
What libraries do you recommend?
解决方案
The best option I can see is Apache Commons Compress with this Maven dependency.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.0</version>
</dependency>
From the examples:
FileInputStream in = new FileInputStream("archive.tar.bz2"); FileOutputStream out = new FileOutputStream("archive.tar"); BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in); final byte[] buffer = new byte[buffersize]; int n = 0; while (-1 != (n = bzIn.read(buffer))) { out.write(buffer, 0, n); } out.close(); bzIn.close();
这篇关于解压缩 BZIP2 档案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文