Organize knowledge and serialization

Finishing knowledge

Knowledge maps
Object

Here Insert Picture Description
For details, please click (Object)

Common API

Here Insert Picture Description
For details, please click (String class)
other common String Math and System

Map

Here Insert Picture Description
For details, please click (Map Tree and use)

File

Here Insert Picture Description
For details, please click

Serialization

concept

Serialization refers to the status information of the object may be converted for storage or transmission process. During serialization, the object status is written to a temporary or permanent storage area, can be read or deserialize status storage area, re-create the object.

Precautions
  1. If a class is required sequence, it is necessary to comply with Serializable interface, to obtain a sequence of numbers.
public class Person implements Serializable {
 /**
  * 序列化编号,这个编号可以自己设也可以系统给定
  */
 private static final long serialVersionUID = 1L;
  1. transient member variables can not be modified sequence of (transient).
method
ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("D:/aaa/person.txt"));
   
// 序列化对象,并且写入到文件中  id = 1 name = "小明"  age = 16
objectOutputStream.writeObject(new Person(1, "小明", 16));

After serialize the contents of
Here Insert Picture Description
deserialization

ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("E:/创建文件/person.txt"));
   
Person person = (Person) objectInputStream.readObject();
//输出为 Person [id=1, name=小明, age=16]
System.out.println(person);

If I add member variables to the Person of the transient, the corresponding member variables when deserialized, its value is the initial value.

Published 10 original articles · won praise 14 · views 2657

Guess you like

Origin blog.csdn.net/weixin_43932553/article/details/104580617