Results 1 to 4 of 4

Thread: [RESOLVED]Help!! Compare and match readLine() and text in a text file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2006
    Posts
    21

    Resolved [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.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2006
    Posts
    21

    Resolved Re: Help!! Compare and match readLine() and text in a text file

    Thanx, i got it working le~

  4. #4
    Lively Member
    Join Date
    Oct 2005
    Posts
    74

    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
  •  



Click Here to Expand Forum to Full Width