本帖最后由 王金科 于 2012-8-23 15:37 编辑
- package cn.study.file;
- import java.io.*;
- public class ObjectStreamDemo {
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception
- {
- //writeObj();
- readObj();
- }
- public static void readObj() throws Exception
- {
- ObjectInputStream ois =
- new ObjectInputStream(new FileInputStream("person.object"));
- Person p = (Person)ois.readObject();
- System.out.println(p);
- ois.close();
- }
- public static void writeObj() throws Exception
- {
- ObjectOutputStream oos =
- new ObjectOutputStream(new FileOutputStream("person.object"));
- oos.writeObject(new Person("李四1",29));
- oos.writeObject(new Person("李四2",29));
- oos.writeObject(new Person("李四3",39));
- oos.close();
- }
- }
复制代码 oos.writeObject(new Person("李四1",29));
oos.writeObject(new Person("李四2",29));
oos.writeObject(new Person("李四3",39));
我添加了3次
readObj(); 中只显示出了第一个,怎么让后面两个在控制台上显示出来啊?
|