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: Can't work out how to read object from .txt file

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can't work out how to read object from .txt file

    I need a method that will be able to load the following from a text file and turn them into Book objects:

    Harbour:John Lindqvist:horror:2006
    Northern Lightshilip Pullman:fantasy:1998
    City of Lost Souls:Cassandra Clare:fantasy:2012
    Robinson Crusoeaniel Defoe:adventure:1719

    The book object has the parameters - String title - String author - String genre - int year(in that order). I can read and save if the title, author and genre are one word each, but I can't work out how to read them if the Strings contain spaces, let alone read the file separating each parameter with the ":".

    Can anyone at least let me know which API I should be using to read objects saved in this format.

    An example method would be amazing, but I understand if that's too lazy of me. I'm new to this forum.

    Thanks heap!!!!


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Can't work out how to read object from .txt file

    Have you read about the String class? What about the Scanner class?
    There are ways to split a string up at a specified string or character. See what some reading can find.

Similar Threads

  1. Program to read .TXT file one line at a time
    By JustForLawls in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 27th, 2012, 02:02 PM
  2. Read .txt file and create objects using data
    By sevans20 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: April 14th, 2012, 01:52 PM
  3. Read txt file into array and create new output.
    By Margaret_Girl87 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 19th, 2012, 12:08 PM
  4. How to make Eclipse work with txt file?
    By Prostak in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 4th, 2011, 05:43 PM
  5. insert(embed) a file object (.txt file) in MS excel sheet using java.
    By jyoti.dce in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 12th, 2010, 08:16 AM