Now write you serialized object Employee into a binary file Program :Step 1 - CodingCreate a text file c:/sunilos/TestWriteEmployee.java and copy below contents.import java.io.FileOutputStream; import java.io.ObjectOutputStream; /** * A program to write in persist data file implemented Serializable interface. */ public class TestWriteEmployee { public static void main(String[] args) throws Exception{ FileOutputStream fileOutputStream = new FileOutputStream("c:/sunilos/sunilos.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOutputStream); Employee emp = new Employee(1,"Sunil","OS"); out.writeObject(emp); out.close(); System.out.println("Obiect is successfully presisted"); } } Step 2 - Deployment
Step 3 - Testing
OutputObiect is successfully presisted NOTE : transient variables do not persist during object serialization or transient variables are discarded during serialization. Go to next program to read(deserialize) an object.. <<Previous | Next>> |