1. Object Stream: writes or reads an object directly. 2. Serialization: convert the object directly into a byte stream to write to the hard disk or Network. 3, If you want to convert an object into a byte stream, the Object's entity class must implement the serializable interface, the serializable interface is a labeled interface, it does not have any method, just to identify that the class can be Serialized. 4, transient keyword, used to modify the member variable, indicating that the member variable is transparent, and the serializable interface with the same, indicating the serialization is not considered when the member Variable. The default value for the data type of the member variable is stored at serialization Time. 5, Externalizable Interface is a subclass of the serializable interface, the implementation of serializable interface JDK will help control how the serialization process, and the implementation of the Externalizable interface can control the implementation of the serialization Process. the interface has two methods: readexternal (objectinput in), and the object is read through Objectinput. writeexternal (objectoutput out); write the object through Objectoutput. in general, let the JDK be implemented, This interface is not commonly Used. Practice Small Examples:package
test.io.object;
Import java.io.FileInputStream;
Import java.io.FileOutputStream;
Import java.io.IOException;
Import java.io.ObjectInputStream;
Import java.io.ObjectOutputStream;
Import java.io.Serializable; public
class objectstreamtest { Public static
void main (String args[]) {
FileOutputStream fos =
null; ObjectOutputStream oos =
null; FileInputStream fis =
null; ObjectInputStream ois =
null;
try { fos =
new fileoutputstream ("e:/technical learning/java/test/socket/objecttest.txt" ); oos =
new objectoutputstream (fos); Stu s =
new Stu (); S. School = "dd" ;Oos.writeobject (s); fis =
new fileinputstream ("e:/technology learning/java/test/socket/objecttest.txt" ); ois =
new objectinputstream (fis); Stu s2 = (Stu) ois.readobject ();System.
out. Print (s2. old + " " + s2.School + " " + s2.name + " " +s2.Teacher); }
catch (classnotfoundexception e) { e.printstacktrace (); }
catch (ioexception e) { e.printstacktrace (); } } }
class Stu
implements serializable{
private static final long Serialversionuid = 1L; int old =;
String name = "bjh";
transient String teacher = "cj"; String school = "lgd"; }Operation Result:dd BJH NULL
Java IO Learning Note (v) Object flow