我正在尝试启动一个进程,然后从输出更新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循环,但我该如何修复呢?
谢谢!