Extraction d'archives RAR
Contents
[
Hide
Show
]Aper�u
L’API Aspose.ZIP permet d’extraire des archives dans vos applications sans avoir recours � d’autres applications tierces. L’API Aspose.ZIP fournit la classe RarArchive pour travailler avec les archives RAR. L’API fournit la classe RarArchiveEntry pour repr�senter un seul fichier dans l’archive RAR.
La cr�ation d’archives RAR n’est pas possible.
Extraire une entr�e
L’exemple de code suivant montre comment extraire une entr�e en utilisant l’instance RarArchive.
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}Extraire une entr�e crypt�e
L’exemple de code suivant montre comment extraire une entr�e crypt�e � l’aide de l’instance RarArchive.
1Fichier fi = nouveau fichier ("encrypted.rar") ;
2try (RarArchive archive = new RarArchive(Files.newInputStream(fi.toPath()))) {
3 try (FileOutputStream destination = new FileOutputStream(dataDir + "firstEntry.txt")) {
4 archive.getEntries().get(0).extract(destination, "p@s$w0rd") ;
5 }
6} catch (IOException ex) {
7 System.out.println(ex) ;
8}Extraction d’un r�pertoire compress�
L’exemple de code suivant montre comment extraire tous les fichiers d’une instance RarArchive.
1try (RarArchive archive = new RarArchive("archive.rar")) {
2 archive.extractToDirectory("extracted") ;
3}