Your class must implements a java.io.Serializable Interface and one more thing is that you have to use java.io.ObjectInputStream and java.io.ObjectOutputStream class to read and write objects respectively.
class apple implements java.io.Serializable
{
int flavor;
String color;
apple(int a, String b)
{
flavor = a;
color = b;
}
}
//.....
apple RedDelicious = new apple(10, "red");
java.io.ObjectOutputStream os=new java.io.ObjectOutputStream(new java.io.FileOutputStream("data.txt"));
os.writeObject(RedDelicious);
os.flush();
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
Offline 6,527 posts
since Oct 2008