Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Is it possible to copy a serializable object to a disk  RSS feed

 
Harini Mamidi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a very limited knowledge of Serialization. Please help me with the following question.
Can we copy a serializable object to a disk, and get the data back when required from the disk?
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this is possible. Use an ObjectOutputStream to write to disk and ObjectInputStream to retrieve from disk.
//Write out object
MyObj obj = new MyObj();
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("myFile.ser"));
os.writeObject(obj);
os.close();
//Read in object
ObjectInputStream in = new ObjectInputStream(new FileInputStream("myFile.ser"));
obj = (MyObj)in.readObject();
[ March 09, 2004: Message edited by: Anthony Watson ]
 
Harini Mamidi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anthony,
Thank you for the reply
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!