Read and extracts from a .rar file. This is a fork of the junrar codebase, formerly on sourceforge.
Code may not be used to develop a RAR (WinRAR) compatible archiver.
- RAR 4 and lower (there is no RAR 5 support)
- password protected archives (also with encrypted headers)
- multi-part archives
- extract from
File
andInputStream
- extract to
File
andOutputStream
Gradle |
implementation "com.github.junrar:junrar:{version}" |
Gradle (Kotlin DSL) |
implementation("com.github.junrar:junrar:{version}") |
Maven |
<dependency> <groupId>com.github.junrar</groupId> <artifactId>junrar</artifactId> <version>{version}</version> </dependency> |
where {version}
corresponds to version as below:
Apache Commons VFS support has been removed from 5.0.0
, and moved to a dedicated repo: https://github.com/junrar/commons-vfs-rar
Junrar.extract("/tmp/foo.rar", "/tmp");
//or
final File rar = new File("foo.rar");
final File destinationFolder = new File("destinationFolder");
Junrar.extract(rar, destinationFolder);
//or
final InputStream resourceAsStream = Foo.class.getResourceAsStream("foo.rar");//only for a single rar file
Junrar.extract(resourceAsStream, tempFolder);
// Assuming you already have an InputStream from the rar file and an OutputStream for writing to
final Archive archive = new Archive(inputStream);
while (true) {
FileHeader fileHeader = archive.nextFileHeader();
if (fileHeader == null) {
break;
}
archive.extractFile(fileHeader, outputStream);
}
final List<ContentDescription> contentDescriptions = Junrar.getContentsDescription(testDocuments);
Junrar.extract("/tmp/foo.rar", "/tmp", "password");
//or
final File rar = new File("foo.rar");
final File destinationFolder = new File("destinationFolder");
Junrar.extract(rar, destinationFolder, "password");
//or
final InputStream resourceAsStream = Foo.class.getResourceAsStream("foo.rar");//only for a single rar file
Junrar.extract(resourceAsStream, tempFolder, "password");
Junrar.extract("/tmp/foo.001.rar", "/tmp");