/*
操作对象的流
ObjectOutputStream
ObjectInputStream
被操作的对象需要实现Serializable(标记接口)
把对象存储在硬盘上。对象的持久化存储。
*/
import java.io.*;
class ObjectStreamDemo
{
public static void main(String[] args) throws IOException,ClassNotFoundException
{
//ObjectOutputStream();
ObjectInputStream();
}
public static void ObjectOutputStream()throws IOException
{
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("obj.txt"));
oos.writeObject(new Person("lisi",20));
oos.close();
}
public static void ObjectInputStream()throws IOException,ClassNotFoundException
{
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("obj.txt"));
Object obj = ois.readObject();
System.out.println(obj);
ois.close();
}
}