Извлечение архивов RAR
Contents
[
Hide
Show
]Обзор
Aspose.zip API позволяет извлекать архивы в ваших приложениях без необходимости каких -либо других сторонних заявок. Aspose.zip API предоставляет Rararchive класс для работы с архивами RAR. API предоставляет класс RararchiveEntry представляющий один файл в архиве RAR.
Создание архивов RAR невозможно.
Извлечь запись
В следующем примере кода демонстрируется, как извлечь запись с помощью экземпляра Rararchive.
1попробуйте (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 байт [] b = новый байт [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}
Извлеките зашифрованную запись
Следующий пример кода демонстрирует, как извлечь зашифрованную запись с помощью экземпляра Rararchive.
1File fi = new File ("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 (назначение, "p@s $ w0rd");
5 }
6} catch (ioException ex) {
7 System.out.println (Ex);
8}
Извлечение сжатого каталога
Следующий пример кода демонстрирует, как все файлы из экземпляра Rararchive.
1попробуйте (rararchive archive = new Rararchive ("archive.rar")) {
2 archive.extracttodirectory («извлечен»);
3}