File I/O HELP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • taskon2
    New Member
    • May 2007
    • 1

    #1

    File I/O HELP

    Hi all

    I am trying to implement a save load class for a text based adventure game....
    A save file must contain 3 arraylists that each contain user defined objects like the players inventory arrayList, the position of all the characters and items in the rooms of the game world.....
    if i manage to write all the arraylists in one file - is this even possible... using append or smthing- then how could i separate them
    when i read back the file to load a game????
    I 've thought of writting a separate file for each arrayList but i dont think thats a good idea.....

    Any pointers?????? HELP
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Why don't you simply serialize your objects? Lists are already Serializable so
    all you have to do is make the objects in the lists Serializable too. It's easy to
    do: just add "implements Serializable" to your classes. The interface is empty
    so there are no methods to implement.

    Wrap an ObjectOutputStr eam around your OutputStream and write your Lists.
    For reading wrap an ObjectInputStre am around your InputStream and read your
    lists back in again.

    kind regards,

    Jos

    Comment

    Working...