mus*_*pax 14
你最好的选择是使用Process课程并阅读Scanner:
Runtime r = Runtime.getRuntime()
Process p = r.exec("tail -f")
Scanner s = new Scanner(p.getInputStream())
while (s.hasNextLine()) {
String line = s.nextLine()
// Do whatever you want with the output.
}
Run Code Online (Sandbox Code Playgroud)
hasNextLine() 应该阻塞,因为它正在等待来自输入流的更多输入,因此您不会忙于等待数据进入.