Uncom preSS BZIP2存档 [英] Uncompress BZIP2 archive

查看:231
本文介绍了Uncom preSS BZIP2存档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以uncom preSS ZIP,gzip和RAR文件,但我还需要uncom preSS bzip2的文件以及解压缩它们(的.tar)。我还没有碰到过一个好的库使用。

我使用Java与Maven相处得最好,我想将它作为在POM的依赖关系。

你推荐什么库?

谢谢,

沃尔特


解决方案

我可以看到最好的选择是阿帕奇共享的COM preSS 这个Maven的依赖关系。

 <&依赖性GT;
  <&的groupId GT; org.apache.commons< /的groupId>
  <&的artifactId GT;公共-COM preSS< / artifactId的>
  <&版GT; 1.0 LT; /版本>
< /依赖性>

范例


在=新的FileInputStream(archive.tar.bz2)

 的FileInputStream;
FileOutputStream中出=新的FileOutputStream(archive.tar中);
BZip2Com pressorInputStream bzIn =新BZip2Com pressorInputStream(中);
最后一个字节[]缓冲区=新的字节[缓冲区大小]
INT N = 0;
而(-1!=(N = bzIn.read(缓冲液))){
  out.write(缓冲液,0,N);
}
out.close();
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?

Thanks,

Walter

解决方案

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();

这篇关于Uncom preSS BZIP2存档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆