Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By jfabian

Thread: reading from a file

  1. #1
    TelliameD is offline Member
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    Default reading from a file

    Hello,

    I'm very new to java and trying to figure out how to read a line of data from a file. Specifically, I'm given a text file with a set of integers on each line. I need to read one line of data at a time and then store all the integers from that line into an array. Question is how can I read one line of data from the file?

    Thanks.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: reading from a file

    Easiest I think is to use a Scanner object that has been constructed with the File as a parameter, and then read in each line with the Scanner. The Scanner Tutorial will give you some guidance, although you will be using the hasNextLine() and nextLine() methods of the Scanner if you are trying to read in lines from the file.

  3. #3
    jfabian is offline Member
    Join Date
    Jun 2012
    Posts
    22
    Rep Power
    0

    Default Re: reading from a file

    Another suggestion is using the class BufferedReader, it bring the readLine() method, which acts as a Buffered of the file and read all the lines. Heres the tutorial: Java Read File Line By Line,How to Read File Line By Line in Java
    Fubarable likes this.

Similar Threads

  1. Reading file external to jar file
    By nn12 in forum New To Java
    Replies: 6
    Last Post: 02-04-2011, 05:46 AM
  2. reading a file and writing to a file....help!!!!
    By java_prgr in forum New To Java
    Replies: 3
    Last Post: 07-26-2010, 06:53 PM
  3. Replies: 9
    Last Post: 10-20-2009, 10:52 AM
  4. Replies: 3
    Last Post: 05-09-2009, 11:31 PM
  5. Reading from csv file.plz help!!!!!!!!!!
    By sanjayksaini in forum New To Java
    Replies: 1
    Last Post: 12-19-2008, 07:41 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
  •