Cold rain Lianjiang night into Wu, Ping Ming Chosan solitary.
Luoyang relatives and friends such as asked, character in the Jade pot.
--Furong building to send Xin gradually
The first way to persist data. It is also possible to break the data out of line-by-row in a file before serialization, and then read it on a line-by-row basis.
such as the Student class
Use the character output stream to store all the properties of the student class in a local file:
Zhang San |18| male
John Doe |18| Women
Read a row, separate data for the student's Name,age,gender, create student objects and join the student collection
Loop up one step until Br.readline = null
It is unclear how this method stores other information about the object.
Here's a list of serialization
On the code:
1 Public classSerializabledemo {2 3 Public Static voidMain (string[] args) throws IOException, ClassNotFoundException {4 //serializes the object obj, saving obj to the local file Obj.bin. Class for object obj must serializable interface5OutputStream OS =NewFileOutputStream ("/home/yanshaochen/public/obj.bin");//OutputStream Abstract class6ObjectOutputStream Oos =NewObjectOutputStream (OS);//ObjectOutputStream Instance Class7Oos.writeobject (obj);//Persistence of obj8 oos.close ();9 //deserializationTenInputStream is=NewFileInputStream ("/home/yanshaochen/public/obj.bin"); OneObjectInputStream Ois =NewObjectInputStream ( is); A@SuppressWarnings ("unchecked") -Object obj = (object) ois.readobject ();//classnotfoundexception exceptions may occur for casts - } the}
Java Learning Notes-serialization and deserialization