public class ObjectOutputStreamDemo {
public static void main(String[] args) {
try (
ObjectOutputStream oot = new ObjectOutputStream(new FileOutputStream("F:\\JAVA\\person.txt"));
){
List<Person> list = new ArrayList<>();
Map<Person,String> map = new HashMap();
Person p1 = new Person("嬴政",54,'男');
Person p2 = new Person("刘邦",50,'男');
Person p3 = new Person("刘秀",58,'男');
list.add(p1);
list.add(p2);
list.add(p3);
map.put(p1,"秦始皇");
map.put(p2, "汉武帝");
map.put(p3, "光武帝");
oot.writeObject(list);
oot.writeObject(map);
oot.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
}