在下面的 while 循环中,我只想从 Process p 的输出中读取最新的行,而忽略在循环休眠时进入缓冲区的任何其他内容。我怎么做?
String s;
Runtime r = Runtime.getRuntime();
Process p = r.exec("SomeContinuousProgram");
myInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
while (true){
if ((s = myInput.readLine()) != null) {
System.out.println(s);
}
Thread.sleep(sleep);
}