public class SerializableObj { public static void main(String[] args) { ObjectOutputStream oos=null; try{ //1.创建ObjectOutputStream输出流 oos =new ObjectOutputStream(new FileOutputStream("D:\\doc\\person.bat")); Person person =new Person("杰米",25,"男"); Person person1=new Person("Lisa",30,"女"); ArrayList<Person>list =new ArrayList<Person>(); list.add(person); list.add(person1); //2.对象序列化,写入输出流 oos.writeObject(list); System.out.println("序列化成功!"); } catch (IOException e) { e.printStackTrace(); }finally { if (oos!=null){ try{ oos.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
标签:输出,ObjectOutputStream,对象,list,Person,oos,new,序列化 From: https://www.cnblogs.com/max-hou/p/18448235