JavaFX,从流程获取信息并更新UI?

时间:2017-05-25 13:00:40

标签: java javafx

我正在尝试启动一个进程,然后从输出更新UI,其中包含信息。这是我目前的代码:

ProcessBuilder pb = new ProcessBuilder()
    .redirectErrorStream(true)
    .command(args);
Process process = pb.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;

while ((line = br.readLine()) != null)
{
    System.out.println(line.trim());
    // Trying to update the UI here
}

问题是该行被输出到控制台,但UI冻结并且没有得到更新。我认为这是因为while循环,但我该如何修复呢?

谢谢!

0 个答案:

没有答案