I am looking for ways to unzip .rar files using Java, and wherever I am, I continue to work with the same tool - JavaUnRar . I look through the unzipped .rar files with this, but all the methods that I think are found for this are very long and inconvenient, as in this example
Currently, I can extract .tar , .tar.gz , .zip and .jar in 20 lines of code or less, so there should be an easier way to extract .rar files, does anyone know
Just if this helps anyone, this is the code I use to extract the .zip and .jar , it works like for
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(); } }
java extract rar
flexinIT
source share