JAVA 序列化类168

package Iodemo;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;

public class ObjectOutputStreamDemo {
    public static void main(String[] args) throws IOException {
        ObjectOutputStream s = new ObjectOutputStream(new FileOutputStream("./1.txt"));
        Student student1 = new Student("zhangsan",18);
        s.writeObject(student1);
        s.close();
      
    }
}
//注意  一个对象想要被序列化,该对象所属的类必须实现Serializable接口
//Serializable 是一个标记接口,实现该接口。不需要重写任何方法
posted @ 2022-04-05 15:30  phpwyl  阅读(19)  评论(0编辑  收藏  举报