import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;public class TestInputStream {
    public static void main(String args[]){
try{
Student s=new Student("0001","张小海",25);
FileOutputStream fos=new FileOutputStream("c:\\zczc.txt");
ObjectOutputStream dos=new ObjectOutputStream(fos);
dos.writeObject(s);
dos.close();
         fos.close();

    }catch (Exception e){
System.out.println(e);
      }    }
}
class Student{
private String id,name;int age; public Student(String id, String name, int age) {
super();
this.id = id;
this.name = name;
this.age = age;
} public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}}

解决方案 »

  1.   

    int age; ---> private int age;
      

  2.   

    private String id,name;int age;\
    ------>>>private String id;
    private String name;
    private int age;类写入文件,还需要implements java.io.Seriealable(单词忘了,序列化谢谢)。
      

  3.   

    class Student implements Serializable需要持久化的类都要实现序列化接口。
      

  4.   

    提示的是什么错误啊?age应该忘记封装了吧。
      

  5.   

    Student  实现 Serializable 接口
      

  6.   

    Student为内部类,要实现序列化接口
    java.io.Serializable
    内部类写法
    class Student implements java.io.Serializable{...}
      

  7.   

    使用对象流之前必须给对象序列化
    将Student类改为这样
    class Student implements Serializable
      

  8.   

    java.io.NotSerializableException: temp.Student想要把一个类的当前状态保存到文件里面,这个类必须实现Serializable标记接口。楼主可以看一下java序列化这一块的知识,网上很多资料