[RESOLVED]Help!! Compare and match readLine() and text in a text file
I have a text file, i open the file and try to match the contents of the text file to a text. Here's my code:
FileInputStream input = new FileInputStream ("BinaryFp.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(input));
for(int i=1;i<801;i++)
{
pdtNo = br.readLine();
if(pdtNo=="M5250")
System.out.println("true");
else
System.out.println("false");
}
The problem is, i don't know why the answer is always false. There should be 1 match. Is ther any way that i can compare "M5250" with text in the text file?
Re: Help!! Compare and match readLine() and text in a text file
You can't compare strings using ==. Use the equals() method.
(This one always gets the newbies.)
Re: Help!! Compare and match readLine() and text in a text file
Thanx, i got it working le~ :)
Re: Help!! Compare and match readLine() and text in a text file
Be sure to mark it resolved.