【发布时间】:2014-08-15 20:50:24
【问题描述】:
我有 .gz 和 .bzip2 文件,我需要提取和显示这些文件。我看了几个地方,它提到使用 zip4j 实用程序。我可以用它来提取和显示文件吗?请告诉我。
我参考了Uncompress BZIP2 archive 的帖子并尝试如下实现,但我不确定要传递给 FileOutputStream 什么,它给了我一个错误。此外,是否可以在解压缩后创建一个文件对象。请协助。再次感谢大家的帮助。
if (getExtension(filename).equals("bz2")) {
try {
FileInputStream fin = new FileInputStream("C:\\temp\\test.bz2");
BufferedInputStream in = new BufferedInputStream(fin);
FileOutputStream out = new FileOutputStream("archive.tar");
BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in);
int buffersize = 1024;
final byte[] buffer = new byte[buffersize];
int n = 0;
while (-1 != (n = bzIn.read(buffer))) {
out.write(buffer, 0, n);
}
out.close();
bzIn.close();
}
catch (Exception e) {
throw new Error(e.getMessage());
}
提前致谢。
~阿克西塔
【问题讨论】: