反序列化是从序列化状态重构对象的过程。 它是序列化的逆操作。 ObjectInputStream
反序列化使用 ObjectOutputStream
写入的对象和原始数据。
import java.io.*;
class Depersist {
public static void main(String args[]) throws Exception {
ObjectInputStream in = new ObjectInputStream(new FileInputStream("asff.txt"));
Student s = (Student) in.readObject();
System.out.println(s.id + " " + s.name);
in.close();
}
}
运行结果如下:
211 welcome to yiibai.com tutorials.