在下面的while循環中,我只想從Process p的輸出中只讀取最新的一行,忽略循環處於休眠狀態時進入緩衝區的任何其他內容。我怎麼做?java Process,getInputStream,只讀最新行
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);
}
謝謝。我意識到在我重新找到它之前,緩衝區中只有大約10行,所以ijust做到了這一點:int c = 0; \t \t \t \t \t \t while((str = marsyasInput.readLine())!= null && c <20)C++; – user1971455