Serialization in a TreeNode program
1 posts in topic
Flat View  Flat View

Posted By:   Anonymous
Posted On:   Sunday, May 5, 2002 06:51 PM

I´m writing a program (implementing TreeNodes) that works as a book editor; each chapter is a different node; and it allows writing and editing of new chapters (nodes).

How can I implement Serialization, in order to make the nodes save the changes and allow me to see those changes every time I compile and run the program?

Re: Serialization in a TreeNode program

Posted By:   Srividya_Vullanki  
Posted On:   Monday, May 13, 2002 02:16 PM

you can write TreeNode object into a file with the following steps.

1.Implement Serializable interface for the TreeNode Program.

2.Write a method which saves the tree node Object
FileOutputStream fos = new FileOutputStream(filename);
ObjectOutputStream oos = new ObjectOutputStream(fos);

U can create the file (filename) manully or programatically.
Then call this method in the tree node program at all such points where the exit of the program is possible.

3.Write a method which reads the object

TreeNode tObject=null;
FileInputStream fin = new FileInputStream(filename);
ObjectInputStream ois = new ObjectInputStream(fin);
tObject = (TreeNode)ois.readObject();

call this method to see the previous object.
About | Sitemap | Contact