Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Pamela Baker   on Jan 21 In Java Category.

  
Question Answered By: Adalia Fischer   on Jan 21

Serializable interface is just only used to tell that this class can
be serialized thats all... no logic  lies there, although you can
serialize your object by

File f0 = new File("d:/abc.obj");
FileOutputStream fos = new FileOutputStream(f0);
ObjectOutputStream os = new ObjectOutputStream(fos);
myObject mo = new myObject();
// do some thing with mo
//......
os.writeObject(mo);
os.flush();
os.close();
and you may deserialize the same object by

FileInputStream fis = new FileInputStream(f0);
ObjectInputStream ois = new ObjectInputStream(fis);
myObject mo2 = (myObject) ois.readObject();
ois.close();

the logic lies in the ObjectOutputStream and ObjectInputStream, you
may also add the variable
static final long serialVersionUID = -1564731489190550833L;
for maintaining the serialized versioning for your class.

Share: 

 
 
Didn't find what you were looking for? Find more on Serialization in java Or get search suggestion and latest updates.


Tagged: