简体   繁体   English

Java-如何从7z读取输出?

[英]Java - How to read output from 7z?

Hy. HY。

I've created a routine that read .tgz files from a directory and unzip each one. 我创建了一个例程,该例程从目录中读取.tgz文件并解压缩每个文件。 I'm using 我正在使用

Process zip01 = Runtime.getRuntime().exec("LINE OF COMMAND");

and

exitVal = zip01.waitFor();

I,m using 7z.exe from its folder to decompress and compress files. 我正在从其文件夹中使用7z.exe解压缩文件。 The command line is working fine. 命令行工作正常。 Now, I what to read the percentage of the decompress and throw it into a textfield or a textarea. 现在,我要读取解压缩的百分比并将其放入文本字​​段或文本区域中。 The graphics part are ok too, s well all the routine. 图形部分也可以,所有常规程序都可以。 The only dificult is to get the realtime percentage of the 7z. 唯一的困难是获取7z的实时百分比。 is there some way to read and show it? 有什么阅读和展示方式吗?

Thanks! 谢谢!

You can get the output of your process like this: 您可以这样获取过程的输出:

Process zip01 = Runtime.getRuntime().exec("LINE OF COMMAND");

BufferedReader output = new BufferedReader(new InputStreamReader(zip01.getInputStream()));
String line;
while ((line = output.readLine()) != null) {

    /* process lines */
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM