序列化 ObjectOutputStream
将内存上所产生的对象保存到一个文本文件中
所有要序列化的类都必须实现Serializable接口
Student implements Serializable{
private static final long serialVersionUID = 1L;
}
反序列化 ObjectInputStream
将本地文件中的内容(对象)--读取到内存上
基本格式:
序列化
准备一个对象
Student stu = new Student(1, "沪青棒");
File file = new File("D:\\stu.bak");
FileOutputStream fos = new FileOutputStream(file);
通过序列化流进行写入ObjectOutputStream
ObjectOutputStream oos = new ObjectOutputStream(fos);
通过序列化流写入一个对象
oos.writeObject(stu);
关闭
oos.close();
fos.close();