Extraction d'archives RAR

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}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.