Question

I wan't to extract a rar file in java. I want to be able to choose where to extract the file as well. I have tried to find a library without any luck. So I tried to use the Runtime.getRuntime().exec() command together with the official rarlabs program. In the terminal it's possible to extract, but when using the same commands in the code, it doesn't work at all. Is this the best way to do it, or should I use some other method? And what am I doing wrong with the Runtime command? Here's a sample code that doesn't work:

Process p = Runtime.getRuntime().exec("cd ~/Desktop/testfolder && /usr/local/bin/unrar x ~/Desktop/test.rar");

I'm using mac by the way.

Was it helpful?

Solution

Use ProcessBuilder and make sure to call inheritIO() on it before buliding your process. Your issue, namely, is buffer overflow on subprocess's stdout. This happens because by defualt you are provided with an InputStream into which the subprocess's stdout is piped and you are responsible for draining it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top