Java ObjectInputStream and ObjectOutputStream Overview
The stream can serialize a basic data and object, or read a basic data and object into the program. Which is to perform the serialization and deserialization operation
The class of the serialized object must implement an example of Serializable interface serialization and deserialization of an object
ObjectOutputStream output = null;
ObjectInputStream input = null;
try {//Create two object product P1 = new Product ("fridge", 1000);
Product P2 = new Product ("TV", 2000);
Create object Output stream = new ObjectOutputStream (New FileOutputStream ("Product.obj"));
Write two objects output.writeobject (p1);
Output.writeobject (p2);
Turn off the output stream output.close ();
Creates an object input stream, reads the persisted object input = new ObjectInputStream (New FileInputStream ("Product.obj"));
Print object Information System.out.println (Input.readobject ());
System.out.println (Input.readobject ());
Close flow input.close (); catch (IOException e) {e.printstacktrace ();} finally {try {if (input!= null) {Input.clo
SE ();
} catch (IOException e) {e.printstacktrace ();
}finally {try {if (output!= null) {output.close ();
} catch (IOException e) {e.printstacktrace (); }
}
} Run results