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

Thread: need help with saving data

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

    Question need help with saving data

    How can I save data from previos runs?
    I need to save the data of object "player" that has the fields:
    String name
    int health
    int strength
    int speed
    I might create more fields

    p.s. I'm a beginner, so please make it as simple as possible
    Last edited by bardd; September 19th, 2010 at 06:59 AM.
    a good programmer can write a Java program in any language


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: need help with saving data

    I need to save the data of object "player" that has the fields:
    Where do you want to save the data? In what format? How will you retrieve that data later?
    For example:
    If you write the data to a file, do you want the contents of the file to be text or can some of it be binary?

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: need help with saving data

    I'm not sure.
    is there some sort of code that cant automatically create a file that saves the data and one that automatically retrives it?
    a good programmer can write a Java program in any language

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: need help with saving data

    Look at the ObjectOutputStream for a way to write the contents of an object. And ObjectInputStream to read it back.

  5. #5
    Member
    Join Date
    Jun 2010
    Posts
    48
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default Re: need help with saving data

    I am not sure, but can the serialization help in this case?

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

    Default Re: need help with saving data

    The easiest way for beginners to do this would be to output all the objects to a text file before the program closes.

    Since your Player class only has 3 attributes, that would be relatively easy to store.

    Google "How to read/write to a text file java" and you will find many examples on how to do this.

    What that will do is write those 3 attributes to a text file then when your program opens up again, it will read from that same file.

Similar Threads

  1. saving data in persian language in mysql db
    By java_cs in forum JDBC & Databases
    Replies: 2
    Last Post: January 19th, 2011, 12:26 PM
  2. saving xml file
    By LOL in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 18th, 2010, 05:45 AM
  3. Help needed regarding saving BLOB in oracle using JSP
    By smsouvik_2008 in forum JDBC & Databases
    Replies: 1
    Last Post: February 26th, 2010, 02:09 AM
  4. [SOLVED] Saving A File?
    By MysticDeath in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: August 1st, 2009, 11:56 AM
  5. How to save statistics of a game in a binary file instead of txt file?
    By FretDancer69 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: June 19th, 2009, 05:05 AM