Search code examples
javafileziparchiverar

How to read rar file comment in java?


I have a directory containing both Zip & Rar archives. I already have a way to get a zip file's comment -

if (f.getName().substring(f.getName().length() - 3).equals("zip")) {
    ZipFile zip = new ZipFile(f);
    zip.getComment();
}

Is there a way to do the same thing on a Rar file?

note that:

  • There are too many rar files for me to manually convert them to zip on some site (If there is some script to convert them, it could work).
  • Renaming a rar file's extension to .zip (file.rar -> file.zip) would still produce an exception when trying to create a new ZipFile object with it.

Thanks in advance!


Solution

  • I think in the end, you are looking for some sort of library to get that done for you. Like raroscope or java-unrar.

    Alternatively, you could decide to re-invent that wheel yourself (not recommended).

    Or you simply run the command line rar tool using ProcessBuilder (as a system command), like explained here.