Answer : To serialize an object into a stream perform the following actions:
- Open one of the output streams, for exxample FileOutputStream
- Chain it with the ObjectOutputStream <- Call the method writeObject() providinng the instance of a Serializable object as an argument.
- Close the streams
Java Code ---------
try{
fOut= new FileOutputStream("c:\\emp.ser");
out = new ObjectOutputStream(fOut);
out.writeObject(employee); //serializing
System.out.println("An employee is serialized into c:\\emp.ser");
} catch(IOException e){ e.printStackTrace();
}
1 comment:
Know more about Java Coding by browsing the below site's code
Herbspro and be healthy. bcoz health is wealth
Post a Comment