Convertir RAR a ZIP

Si quieres convertir archivos RAR a ZIP lee este art�culo.

Conversi�n

La API de Aspose.ZIP proporciona la clase RarArchive para extraer archivos RAR. Podemos extraer una entrada a la memoria sin guardarla en un almacenamiento intermedio y pasarla al archivo ZIP inmediatamente.

Aseg�rese de que tiene suficiente memoria virtual para mantener el contenido de todas las entradas.

Transferir una entrada

El siguiente ejemplo de c�digo demuestra c�mo extraer entradas de un archivo RAR y ponerlas inmediatamente en un archivo ZIP. Las entradas que son directorios a�adidos con barra inclinada para especificar su tipo.

 1try (Archivo zip = nuevo Archivo()) {
 2    try (RarArchive rar = new RarArchive("D:\\archvie.rar")) {
 3        for (int i = 0; i < rar.getEntries().size(); i++) {
 4            RarArchiveEntry entry = rar.getEntries().get(i);
 5            if (!entry.isDirectory()) {
 6                try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
 7                    entry.extract(out);
 8                    try (ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray())) {
 9                        zip.createEntry(entry.getName(), in);
10                    }
11                }
12            } else {
13                zip.createEntry(entry.getName() + "/", new ByteArrayInputStream(new byte[0]));
14            }
15        }
16    }
17    zip.save("salida.zip");
18} catch (IOException ex) {
19    System.out.println(ex);
20}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.