我有一个使用7zip来解压缩文件的应用程序。我使用的代码如下:
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();其中路径是文件的位置,temp_path是解压缩的位置。
虽然这在我的电脑中很好,但我的同事在运行同一应用程序时会出错。
在我的计算机中,变量exitVal的值由waitFor方法设置为0。在另一台计算机中,我看到这个变量设置为1 (ERROR_INVALID_FUNCTION)。这款应用程序在两台电脑上都是一样的,无论是使用win xp还是使用相同版本的7zip,我还会错过什么呢?
谢谢你的帮忙!
编辑:
我发现了这两台电脑的区别。已经安装了java 7,而有问题的则安装了java 6。
发布于 2012-04-11 11:12:53
如果使用zip文件,最好看看ZipInputStream和ZipOutputStream。这样,您就不必依赖可能存在也可能不存在的工具。
如果您使用的是.7z文件(使用LZMA压缩),则有一个名为伊兹马吉奥的库,它也将为您提供java流。
资源:
https://stackoverflow.com/questions/10104589
复制相似问题