title: Using java to extract .rar files
body: <p>I am looking a ways to unzip <code>.rar</code> files using Java and where ever I search i keep ending up with the same tool - <code>JavaUnRar</code>. I have been looking into unzipping <code>.rar</code> files with this but all the ways i seem to find to do this are very long and awkward like in <a href="https://github.com/edmund-wagner/junrar/blob/6f32323c983015d96c64084418793853f514b519/testutil/src/main/java/de/innosystec/unrar/testutil/ExtractArchive.java" rel="noreferrer">this example</a></p>
  
  <p>I am currently able to extract <code>.tar</code>, <code>.tar.gz</code>, <code>.zip</code> and <code>.jar</code> files in 20 lines of code or less so there must be a simpler way to extract <code>.rar</code> files, does anybody know?</p>
  
  <p>Just if it helps anybody this is the code that I am using to extract both <code>.zip</code> and <code>.jar</code> files, it works for both</p>
  
  <pre><code> public void getZipFiles(String zipFile, String destFolder) throws IOException {
      BufferedOutputStream dest = null;
      ZipInputStream zis = new ZipInputStream(
                                         new BufferedInputStream(
                                               new FileInputStream(zipFile)));
      ZipEntry entry;
      while (( entry = zis.getNextEntry() ) != null) {
          System.out.println( "Extracting: " + entry.getName() );
          int count;
          byte data[] = new byte[BUFFER];
  
          if (entry.isDirectory()) {
              new File( destFolder + "/" + entry.getName() ).mkdirs();
              continue;
          } else {
              int di = entry.getName().lastIndexOf( '/' );
              if (di != -1) {
                  new File( destFolder + "/" + entry.getName()
                                               .substring( 0, di ) ).mkdirs();
              }
          }
          FileOutputStream fos = new FileOutputStream( destFolder + "/"
                                                       + entry.getName() );
          dest = new BufferedOutputStream( fos );
          while (( count = zis.read( data ) ) != -1) 
              dest.write( data, 0, count );
          dest.flush();
          dest.close();
      }
  }
  </code></pre>