Results 1 to 2 of 2

Thread: File Reading

  1. #1
    nuggetman4 is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default File Reading

    How do I finish this code using a While loop to read each line of a BufferedFileReader into the fileData ArrayList. I cant alter the following code I can only add to it.

    Java Code:
    ArrayList<String> fileData = new ArrayList<String>();
    //Assume file.txt contains the lines of data i need and is in current directory
    BufferedFileReader reader = new BufferedFileReader(new FileReader("file.txt"));
    
    String currentLine = "";
    eof = false;
    Last edited by nuggetman4; 05-10-2010 at 07:06 PM. Reason: To clarify

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    I recommend to use code like a

    Java Code:
    BufferedFileReader in = new BufferedFileReader(); 
    for (int i=0; i < nargs; i++) { 
        try { 
            in.open(args[i]); 
            while ((line = in.readLine()) != null) { //<-----
                nlines++; 
            } in.close(); 
    } catch (Exception e) { 
        System.out.println(" BFRTest: exception:" + e ); 
    }
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

Similar Threads

  1. Reading a file
    By fenwick in forum New To Java
    Replies: 19
    Last Post: 02-22-2010, 04:01 AM
  2. Replies: 9
    Last Post: 10-20-2009, 10:52 AM
  3. Replies: 3
    Last Post: 05-09-2009, 11:31 PM
  4. reading csv file help
    By fritz1474 in forum New To Java
    Replies: 5
    Last Post: 09-04-2008, 08:41 PM
  5. Reading from a file
    By leebee in forum New To Java
    Replies: 1
    Last Post: 07-23-2007, 12:02 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
  •