Results 1 to 3 of 3
  1. #1
    busdude is offline Member
    Join Date
    Oct 2008
    Rep Power

    Default Filereader finding specific characters

    I need to use a filereader to read from a text file that has a format like:

    .I 1
    .I 2

    I need the filereader to recognize when it sees a ".I" and then save the number immediately following it on the same line onto a variable, then after that recognize a ".T" and save all text in the following line into another variable and then after that recognize ".W" and save all lines of text after that up until the next ".I" and keep repeating the process until the file is done

    I'm trying to get it top stop at certain points but it doesn't work

    Java Code:
    try {
    	    BufferedReader in = new BufferedReader(new FileReader("cacm.all"));
    	    String str;
    	    while ((str = in.readLine()) != ".T") {
    	} catch (IOException e) {
    I don't know how to get it work.

    Also is bufferedReader the best choice for this or is there something else better?

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Rep Power

    Default Re: Filereader finding specific characters

    Use String#contain(); for compare string. and don't use ==. It is not correct.
    Skype: petrarsentev

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Filereader finding specific characters

    Separate the reading of the String from the testing of the String's value. Make it be two statements so that you can make all the tests of the String that you need to do.
    First read the String into a variable.
    Then make the tests of the String's contents

Similar Threads

  1. Using UNBUFFERED FileReader.
    By Spooge in forum New To Java
    Replies: 1
    Last Post: 10-11-2010, 08:03 AM
  2. FileReader help
    By emp in forum New To Java
    Replies: 1
    Last Post: 07-28-2009, 04:41 AM
  3. add FileReader to GUI
    By VinTiger in forum New To Java
    Replies: 8
    Last Post: 05-11-2009, 12:23 AM
  4. Replies: 2
    Last Post: 11-08-2008, 10:40 AM
  5. finding Operating System specific data
    By FrankyDee in forum New To Java
    Replies: 2
    Last Post: 09-28-2007, 03:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts