Keep track of the previous line read in in a String variable, which you can initialize as an empty string. When you read in each line, check whether it's equals()
to the previously stored line in that variable. If so, do what you want to do, like Thread.sleep()
. Otherwise save the current line into that variable. In code:
BufferedReader reader = new BufferedReader(new FileReader("foo.txt"));
String foo = "";
String old = "";
while((foo = reader.readLine()) != null) {
if(foo.equals(old)) {
System.out.println("Sleeping...");
Thread.sleep(1000);
} else {
old = foo;
}
}