タールアーカイブの使用方法

tarの目的

Tar Archive複数のファイルを単一のファイルに結合することができます。ジョイントファイルも圧縮できます。

圧縮なしで収集

Tarアーカイブに2つのファイルを収集するサンプルがあります。

 1try(fileoutputStream tarfile = new fileoutputStream( "goint.tar")){
 2    ファイルfi1 = new file( "text.txt");
 3    ファイルfi2 = new file( "picture.png");
 4
 5    try (TarArchive archive = new TarArchive()) {
 6        archive.createEntry("text.txt", fi1);
 7        archive.createEntry("picture.png", fi2);
 8        archive.save(tarFile);
 9    }
10} catch(ioException ex){
11    System.out.println(ex);
12}

TARアーカイブの圧縮

UNIXのようなオペレーティングシステムでは、「TAR」ユーティリティを使用すると、TARアーカイブを作成して作成時にGZIPに圧縮できます。 Aspose.Zipは、 SaveGziptメソッドと同様の機能を提供します。

1try(tararchive archive = new Tararchive()){
2    archive.createentry( "text.txt" "d:\\ texts \\ article.txt");
3    archive.createentry( "picture.png" "d:\\ picture \\ photo.png");
4    archive.savegzipt( "result.tar.gz");
5}

最近 XZ UtilityはLinuxとUnixで人気があります。 TARの圧縮は、Asops.Zipにシームレスに統合されています。 TARアーカイブの SavexzCompressed方法を使用します。

1try(tararchive archive = new Tararchive()){
2    archive.createentry( "text.txt" "d:\\ texts \\ article.txt");
3    archive.createentry( "picture.png" "d:\\ picture \\ photo.png");
4    archive.savexzcompressed( "result.tar.xz");
5}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.