• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing objects to files and reading them back into the UI

 
Hector Rivera
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to the java scene, and I need help on how to Write objects to files and reading them back into the UI.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hector,
Java makes it almost too easy to persist objects to a file. The classes your are interested in are ObjectOutputStream and ObjectInputStream.
Here's an example:

Note that the objects that you write to the object stream must implement either Serializable or Externalizable.
Hope this helps,
Michael Morris
 
ali rafiq
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have also a Question about this class
we are saving an object in a test.out ..
Do we save two or more than two object in test.out file. ?
if they save more then two object. then how do we call second or another object?
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ali,
You keep calling readObject(), readInt(), readUTF(), or whatever. You just have to be sure that you read everything back in the same order that they wer written.
Hope this helps,
Michael Morris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic