Java Learning Notes-serialization and deserialization

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.