How to write an Object to a file

Java object can be written into a file for future reference. This process is called Serialization (translating data structures or object state into a format that can be store). In order to do that, we have to implement the Serializable interface, and use ObjectOutputStream to write object into a file.

FileOutputStream fout = new FileOutputStream("c:\\temp\\address.txt");
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(address);