Reputation: 2571
I have an application that uses 7zip in order to unzip a file. The code I use is the following:
Runtime prog = Runtime.getRuntime();
Process proc = prog.exec(System.getenv("ProgramFiles").concat("\\7-Zip\\7z x " + "\""+path+"\""+ " -o"+Values.temp_path));
InputStream stderr = proc.getErrorStream();
InputStream instr = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(stderr);
InputStreamReader insr = new InputStreamReader(instr);
BufferedReader br = new BufferedReader(isr);
BufferedReader br2 = new BufferedReader(insr);
String line = null;
String line2 = null;
while ( (line = br.readLine()) != null & (line2 = br2.readLine()) != null){}
int exitVal = proc.waitFor();
Where path is the file's location and temp_path the location where it will be unzipped.
While this works fine in my computer, I have colleagues that get errors when they run this same app.
In my computer, the value of the variable exitVal is set to 0 by the method waitFor. In other computer I've seen this variable set to 1 (ERROR_INVALID_FUNCTION). The app is the same in both computers, both using win xp and the same version of 7zip, what else could I be missing?
Thanks for your help!
EDIT:
I found the difference between the 2 computers. The one that works has java 7 installed, while the one with the issue has java 6
Upvotes: 2
Views: 2267
Reputation: 93187
If you're using zip files, you better take a look at ZipInputStream and ZipOutputStream. This way you won't have to rely on a tool that may or may not be there.
If you're using .7z files (compressed with LZMA
), there is a library named lzmajio that will also give you java Streams.
Resources:
Upvotes: 3