File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing Serializable Objects in files

 
Anish Yadav
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me how to store a object into a file and later on restore it.
 
Matt Senecal
Ranch Hand
Posts: 255
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't too difficult. When writing the objects to a file you need to make sure that their integrity as java objects is retained. This is done through serialization. An object that is serializable can be successfully serialized (converted to a serial format) and unserialized.
To write an object to a file, all you need to do is something like this:

To read the object from the file you just do the opposite:

That's all there is to it!
Originally posted by Anish Yadav:
Can anyone tell me how to store a object into a file and later on restore it.

[This message has been edited by Matt Senecal (edited April 30, 2001).]
[This message has been edited by Matt Senecal (edited April 30, 2001).]
 
surya_java
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey matt!
every thing iss fine with ur code. but dont u think the object class should implement serializable interface ?.
surya .
 
Matt Senecal
Ranch Hand
Posts: 255
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's true, but the question wasn't about the type of object being serialized.
Originally posted by surya_java:
hey matt!
every thing iss fine with ur code. but dont u think the object class should implement serializable interface ?.
surya .

 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic