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(); } } |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |