Need help with junrar?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

junrar
172 Stars 63 Forks Other 251 Commits 2 Opened issues

Description

Plain Java unrar library

Services available

!
?

Need anything else?

Contributors list

Build Status Download codecov

Junrar

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.

Supported features

  • RAR 4 and lower (there is no RAR 5 support)
  • password protected archives (also with encrypted headers)
  • multi-part archives
  • extract from
    File
    and
    InputStream
  • extract to
    File
    and
    OutputStream

Installation

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:
  • Java 8 Version: Download
  • Java 6 Compatible Version: Download

Apache Commons VFS support has been removed from

5.0.0
, and moved to a dedicated repo: https://github.com/junrar/commons-vfs-rar

Usage

Extract from a file to a directory:

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);

Extract from an InputStream to an OutputStream

// 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); 
  }

List files

final List contentDescriptions = Junrar.getContentsDescription(testDocuments);    

Extract a password protected archive

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");

Extract a multi-volume archive

Junrar.extract("/tmp/foo.001.rar", "/tmp");

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.