BZIP2アーカイブを解凍する 質問する

BZIP2アーカイブを解凍する 質問する

zip、gzip、rar ファイルを解凍できますが、bzip2 ファイルを解凍してアーカイブ (.tar) を解凍する必要もあります。使用できる適切なライブラリが見つかりません。

私は Maven と一緒に Java を使用しているので、理想的には、それを POM の依存関係として含めたいと思います。

どのライブラリをお勧めしますか?

ベストアンサー1

私が考える最良の選択肢はApache Commons 圧縮この Maven 依存関係を使用します。

<dependency>
  <groupId>org.apache.commons</groupId>
  <artifactId>commons-compress</artifactId>
  <version>1.0</version>
</dependency>

から:

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

おすすめ記事