3

Is there any java library by which we can compress a plain text file(.txt) into winRAR format(.rar). I have been searching in google but couldn't find any relevant library which does that.

JavaGeek
  • 1,535
  • 9
  • 39
  • 63
  • Seems duplicate of http://stackoverflow.com/questions/561107/rar-archives-with-java – Aleks G Jan 10 '12 at 13:56
  • take a look here http://www.catacombae.org/jlrarx.html#rarlib and then here http://www.unrarlib.org/ wrapping a jni layer on this should be no problem. – BigMike Jan 10 '12 at 14:01

7 Answers7

7

you can always do

Runtime.getRuntime().exec("rar -a somefile.txt"); 
dov.amir
  • 11,489
  • 7
  • 45
  • 51
  • This looks good. But do we have control on the process once it gets rared? Bcoz i want to copy that RAR to some other location – JavaGeek Jan 10 '12 at 14:00
  • 1
    create a temp directory, rar the files to that directory, copy the context of the temp directory to where you want, and then delete the temp directory, you can do that with a bach script and have Runtime.getRuntime().exec call the script – dov.amir Jan 10 '12 at 14:08
3

I think RAR is not open-source format. I'd rather use ZIP - it's built-in in Java.

Piotr Gwiazda
  • 12,080
  • 13
  • 60
  • 91
2

RAR is a proprietary format, and I don't know of any library to create it (although there seem to be some that can read it). Any reason why you wouldn't use another, more open format like 7zip (for compression), or plain Zip (for universal compatibility)?

Amadan
  • 191,408
  • 23
  • 240
  • 301
  • +1 RAR is both proprietary and closed. I've always wondered why it has such traction in the geek culture. – leonbloy Jan 10 '12 at 14:02
  • I didn't try 7zip but for Zip the limitation is only 4 GB. we cannot zip more than 4 GB file. – JavaGeek Jan 10 '12 at 14:02
  • 1
    4Gb limit was long in Java, but apparently [no more](http://blogs.oracle.com/xuemingshen/entry/zip64_support_for_4g_zipfile) (I didn't test it myself, though). 7z supports [files with sizes up to 16000000000 GB](http://www.7-zip.org/7z.html). – Amadan Jan 10 '12 at 14:25
1

One reason to use RAR: It is sooooo much better than ZIP. For example: One of our production print files has a lot of repetition (including images) in it. 142 MB large, it zips to about 80MB. RAR seems to detect these repetitions and the resulting file is not even 2MB!

Radboud
  • 81
  • 5
1

(From the question, of which this one is a duplicate - RAR archives with java)

You could try JUnRar, "a RAR handling API implemented in pure Java" (quoting the site).

Community
  • 1
  • 1
Aleks G
  • 56,435
  • 29
  • 168
  • 265
1

No you can not do it. Only WinRAR can create rar file. There is only a unrar library for it.

Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187
0

Why RAR? as others have mentioned, RAR is not open.

Java has native ZIP API. Java Zip API: How to Create a Zip File Using Java

Robert Hume
  • 1,129
  • 2
  • 14
  • 25
TS-
  • 4,311
  • 8
  • 40
  • 52