This is my Java code to read text from a text file
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class checking {
public static void main(String[] args) throws IOException {
// Create a BufferedReader from a FileReader.
BufferedReader reader = new BufferedReader(new FileReader("pw.txt"));
// Loop over lines in the file and print them.
while (true) {
String line = reader.readLine();
if (line == null) {
break;
}
System.out.println(line); // The output is abc
if(line=="abc"){
System.out.println("true");
} else {
System.out.println("false"); //However it show false...
}
}
// Close the BufferedReader.
reader.close();
}
}
Inside pw.txt, there is only one line which the only text in there was abc.
I did an if statement to check if the line is equal to "abc" however the output was false... which I don't quite understand.
Did I made any stupid mistakes?