为何读出来的对象是null,代码:
import java.io.*;
import java.util.ArrayList;
public class NewClass {
public static void main(String[] args) throws ClassNotFoundException,IOException{
try(ObjectOutputStream output =new ObjectOutputStream(new FileOutputStream("didi.dat"));){
output.writeObject(new Student_2("林琅天","河南","17723526243","3220063463@qq.com",3));
}
try(ObjectInputStream input =new ObjectInputStream(new FileInputStream("didi.dat"));){
Student_2 hh=(Student_2)(input.readObject());
System.out.println(hh.toString());
System.out.print(hh);
}
}
}
结果是这样的:Student null null null null 3
Student null null null null 3成功构建 (总时间: 0 秒)