0
点赞
收藏
分享

微信扫一扫

序列化对象输出

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();
                }
            }
        }
    }
}

 



举报

相关推荐

0 条评论