对象操作流:
ObjectOutputStream,把对象进行序列化 序列化:将对象写到文件上,相当于存档
Person p1 = new Person("xx",23); 反序列化:相当于读档
oos.writeObject(p1); 可以把多个person对象存入ArrayList,直接写出list
*实现Serializable接口的对象才可以被序列化
ObjectInputStream反序列化:
ObjectInputStream ois = new ObjectInputStream(new FileInputSrteam("x.txt"));
Person p1 = (Person)ois.readObject();
EOFException:文件已读到了末尾异常
end of file |
|