Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: BufferedReader

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default BufferedReader

    Hi, i need your help...

    private static LinkedList lines = new LinkedList();
    ...
    public static void read() throws IOException{
            try {
            String sCurrentLine;
            BufferedReader br =
                 new BufferedReader(new FileReader("forum.log"));
            String[] line = null;
            while ((sCurrentLine = br.readLine()) != null) {
                    System.out.println(sCurrentLine);
                   line = sCurrentLine.split(",");
                   lines.add(line);
             }
            br.close();
            lines.toArray(new String[lines.size()]);
            for(int i=0; i<=lines.size(); i++)
                System.out.println(lines.get(i));
        } catch (FileNotFoundException e) {
     
          e.printStackTrace();
     
        } catch (IOException e) {
     
          e.printStackTrace();
     
        }
     
      }

    In the linked list lines i want to save the words separated by "," but it gives me some exceptions and im not sure if that code does that...

    Help me please
    Tks


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: BufferedReader

    What exception are you getting? Please post the entire error message.

  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: BufferedReader

    My guess might be this line:
    lines.add(line);

    Can you add an array to a LinkedList? I know there is an addAll(Collection<? extends E> c) method, but I don't think the standard add(E e) method lets you send it a String[]. Not sure though.

    Continuing on that thought, this line:
    lines.toArray(new String[lines.size()]);
    will do nothing, since the toArray(T[] a) method returns a <T> T[], which you do not capture.
    Last edited by aussiemcgr; November 20th, 2010 at 12:17 PM.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. BufferedReader error?
    By Umogrim in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 28th, 2010, 08:51 PM
  2. Problem in BufferedReader
    By shamed in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: December 1st, 2009, 04:30 PM
  3. Scanner vs BufferedReader?
    By Bill_H in forum File I/O & Other I/O Streams
    Replies: 11
    Last Post: October 27th, 2009, 09:44 AM
  4. (.readLine() method) of BufferedReader class
    By chronoz13 in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: October 13th, 2009, 06:59 PM
  5. Java error while using BufferedReader class to read a .txt document
    By Jchang504 in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: February 4th, 2009, 07:55 PM