In the while loop below I want to read only the newest line from Process p's output, ignoring anything else that entered the buffer while the loop was sleeping. How do I do that?
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);
}