|
-
Dec 11th, 2006, 02:19 AM
#1
Thread Starter
Junior Member
[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?
Last edited by huiling25; Jan 30th, 2007 at 04:20 AM.
-
Dec 11th, 2006, 08:16 AM
#2
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.)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 13th, 2006, 04:09 AM
#3
Thread Starter
Junior Member
Re: Help!! Compare and match readLine() and text in a text file
Thanx, i got it working le~
-
Dec 13th, 2006, 03:36 PM
#4
Lively Member
Re: Help!! Compare and match readLine() and text in a text file
Be sure to mark it resolved.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|