gpt4 book ai didi

Java - 运行 7zip

转载 作者:行者123 更新时间:2023-12-04 05:50:32 26 4
gpt4 key购买 nike

我有一个使用 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();

其中 path 是文件的位置,temp_path 是解压缩文件的位置。

虽然这在我的电脑上运行良好,但我的同事在运行相同的应用程序时会出错。

在我的计算机中,变量 exitVal 的值通过方法 waitFor 设置为 0。在其他计算机中,我看到此变量设置为 1 (ERROR_INVALID_FUNCTION)。该应用程序在两台计算机上都是相同的,都使用 win xp 和相同版本的 7zip,我还能缺少什么?

感谢您的帮助!

编辑:

我发现了两台电脑之间的区别。有效的安装了 java 7,而有问题的安装了 java 6

最佳答案

如果您使用 zip 文件,最好查看 ZipInputStreamZipOutputStream .这样您就不必依赖可能存在也可能不存在的工具。

如果您使用 .7z 文件(用 LZMA 压缩),则有一个名为 lzmajio 的库这也将为您提供java Streams。

资源:

  • contrapunctus.net: LZMA Streams in Java
  • 7-zip SDK
  • oracle.com: Compressing and Decompressing Data Using Java APIs
  • 关于Java - 运行 7zip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10104589/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com