本帖最后由 杨锦 于 2012-9-5 21:57 编辑
public class ObjectOutDemo {
public static void main(String[] args) throws IOException, IOException {
Person p1 = new Person("张三",15);
Person p2 = new Person("李四",32);
Person p3 = new Person("王五",23);
Person p4 = new Person("赵六",22);
ArrayList<Person> list = new ArrayList<Person>();
Collections.addAll(list, p1,p2,p3,p4);
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("obj.txt"));
oos.writeObject(list);
oos.close();
}
}
|