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

    Default Filereader finding specific characters

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

    .I 1
    .T
    text
    .W
    text
    text
    .I 2
    etc.

    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") {
    	    	System.out.println(str);
    	    
    	    }
    	    in.close();
    	} 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
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default Re: Filereader finding specific characters

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

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    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, 09:03 AM
  2. FileReader help
    By emp in forum New To Java
    Replies: 1
    Last Post: 07-28-2009, 05:41 AM
  3. add FileReader to GUI
    By VinTiger in forum New To Java
    Replies: 8
    Last Post: 05-11-2009, 01:23 AM
  4. Replies: 2
    Last Post: 11-08-2008, 11:40 AM
  5. finding Operating System specific data
    By FrankyDee in forum New To Java
    Replies: 2
    Last Post: 09-28-2007, 04: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
  •