本帖最后由 侯凯斌 于 2013-2-18 11:46 编辑
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("张五",13);
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();
}
} |
|