Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By goldest

Thread: Read specific lines

  1. #1
    AA++ is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default Read specific lines

    First of all sorry for my bad english

    i have a text file and look like this.

    username score
    aa 70
    java 50
    aa 40

    i want to do list only username: aa on output but i can't do this can you help me ?
    Thanks.

  2. #2
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by AA++ View Post
    can you help me ?
    With what do you need help? What have you tried for this?

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  3. #3
    AA++ is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default

    PHP Code:
    ArrayList<String> fields = new ArrayList<String>();
            
            String line;
            try {
                BufferedReader br = new BufferedReader(new FileReader("scored.txt"));
                while ((line = br.readLine()) != null) {
                    if(line.startsWith("a")){
                        System.out.println(line);
                    }
                   
                }
                br.close();
            } catch (Exception e) {//Catch exception if any
                System.err.println("Error: " + e.getMessage());
            }
    its only write single line. i want write to output all starts with "a"

  4. #4
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by AA++ View Post
    its only write single line.
    For me it gave two lines.
    Java Code:
    aa 70
    aa 40
    Which output do you get?
    AA++ likes this.
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  5. #5
    AA++ is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default

    sorry my text file have only one starts with "a" :) i forgot edit my text file
    Thank you so much
    My program is working.

  6. #6
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Default

    Quote Originally Posted by AA++ View Post
    My program is working.
    Well, that's the best feeling sometimes. Anyways, glad to know that your problem is solved.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

Similar Threads

  1. read specific data from the internet
    By Get_tanked in forum New To Java
    Replies: 1
    Last Post: 02-01-2011, 03:47 AM
  2. Replies: 5
    Last Post: 11-17-2010, 05:53 PM
  3. Replies: 4
    Last Post: 11-03-2010, 06:17 PM
  4. read char words lines
    By Drukqs in forum New To Java
    Replies: 6
    Last Post: 05-14-2009, 06:14 PM
  5. Reading specific lines
    By ivvgangadhar in forum New To Java
    Replies: 8
    Last Post: 01-12-2009, 08:53 AM

Posting Permissions

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