从文件中读取矢量

时间:2015-12-14 20:35:05

标签: java

我想在文件中写一个Vector<Person>然后希望阅读它。

写入文件:

ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("FileName"));
    Vector<Person> People = new Vector<Person>();
    People.addElement(new Person("first_name","last_name","address"));
    People.addElement(new Person("first_name2","last_name2","address"));

    oos.writeObject(People);
    oos.flush();
    oos.close();

阅读:

ObjectInputStream ois = new ObjectInputStream(new FileInputStream("FileName"));

Vector<Person> P = (Vector<Person>) ois.readObject();
ois.close();

for(int i=0; i<P.size(); i++){
    System.out.println(P.elementAt(i).toString());
}

但似乎在演员阵容中存在问题......有人可以帮忙吗? 感谢。

0 个答案:

没有答案