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 2 of 2

Thread: Reading data from a text file into an object

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Reading data from a text file into an object

    Lets say I have several lines of data in a text file...ex...

    Joe Stevens M 40 5
    Maya Moore F 39 3
    Bo Johnson  M 25 4

    I want to put all this data into a "payroll" object for later use. If it was just one line I would be done...

    String line = in.readLine();
     
    Payroll one = new Payroll(line);

    any help appreciated


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Reading data from a text file into an object

    Not sure at which step the problem is so if the following doesn't help please be more specific....to read the file line by line, just loop over the Stream until readLine returns null (which is the end of the file). If you are to create a new Payroll on a line-by-line basis, then add them to an array or a List for later use

Similar Threads

  1. Replies: 8
    Last Post: March 25th, 2011, 02:34 PM
  2. reading string in from text file
    By basketball8533 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: December 3rd, 2010, 05:31 PM
  3. Reading a lines from text file
    By kiran in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: September 26th, 2010, 10:54 PM
  4. [SOLVED] Reading from a text file and storing in arrayList
    By nynamyna in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 26th, 2010, 09:55 PM
  5. Reading from a text file. Help needed urgently.
    By TheAirPump in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: December 14th, 2009, 06:16 PM