Here's my code. I'm trying to read this text file:
AAA
BBB
CCC
DDD
In the code below, BufferedReader should stop at the line "DDD", but program goes in loop.
I tried to replace "DDD" with null and it worked, but I want it stop at the line I specified! I'm stucked in this issue and I don't know how to solve it... solution?
import java.io.*;
public class Reading{
public Reading() {}
public static void main(String[] args) throws IOException{
new Reading();
BufferedReader br = new BufferedReader(new FileReader(new File("test.txt")));
String line;
while((line = br.readLine()) != "DDD"){
System.out.println(line);
}
br.close();
}
}