RARアーカイブの抽出
Contents
[
Hide
Show
]概要
Aspose.Zip APIでは、他のサードパーティアプリケーションを必要とせずにアプリケーションでアーカイブを抽出できます。 Aspose.Zip APIは、 RararchiveクラスをRARアーカイブで動作させます。 APIは、 RararchiveEntryクラスを提供して、RARアーカイブ内の単一のファイルを表します。
RARアーカイブの作成は不可能です。
エントリを抽出
次のコードの例は、恐ろしいインスタンスを使用してエントリを抽出する方法を示しています。
1try(rararchive archive = new Rararchive( "archive.rar")){
2 try(fileoutputStream destination = new fileoutputStream(datadir + "firstentry.txt")){
3 try(inputstream source = archive.getentries()。get(0).open()){
4 byte [] b = new byte [1024];
5 int bytesRead;
6 while(0 <(bytesread = source.read(b、0、b.length))){
7 destination.write(b、0、bytesread);
8 }
9 }
10 }
11} catch(ioException ex){
12 System.out.println(ex);
13}
暗号化されたエントリを抽出
次のコードの例は、arrarchiveインスタンスを使用して暗号化されたエントリを抽出する方法を示しています。
1ファイルfi = new file( "necrypted.rar");
2try(rararchive archive = new Rararchive(files.newinputStream(fi.topath()))){
3 try(fileoutputStream destination = new fileoutputStream(datadir + "firstentry.txt")){
4 archive.getentries()。get(0).extrage(destination、 "p@s $ w0rd");
5 }
6} catch(ioException ex){
7 System.out.println(ex);
8}
圧縮ディレクトリの抽出
次のコードの例は、Rararchiveインスタンスからすべてのファイルへの方法を示しています。
1try(rararchive archive = new Rararchive( "archive.rar")){
2 archive.extracttodirectory( "抽出");
3}