我正在通过 runtime.exec 运行一个命令,这需要一些时间。我想在此期间更新我的 ProgressBar。
我已经得到了我想要的系统输出,问题是:当这个过程完成时,我一下子得到了它。而不是一步一步更新我的ProgressBar ...
这是一些代码
public Runtime rt = Runtime.getRuntime();
public Process pp;
public doit() {
try {
pp = rt.exec(a_long_timed_process);
InputStream is = pp.getErrorStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null) {
if (line.contains("In:")) {
int a = line.indexOf("In:"); //get a string
int b = line.lastIndexOf("%"); //between
String lineout = line.substring(a + 3, b);//"0.00" and "99.99"
double nr = Double.parseDouble(lineout); //make it a double
int round = (int) nr; //make it a usable int
System.out.println(round);
myProgressBar.setValue(round); //UPDATE Progressbar
}
}
pp.waitFor();
} catch (IOException ex) {
Logger.getLogger(Sox.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(Sox.class.getName()).log(Level.SEVERE, null, ex);
}
}
感谢您的每一个帮助
在此先感谢