import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.List;
public class ObjectInputMore {
public static void main(String[] args) throws Exception {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("io/students"));
// 本来应该是Object obj = ois.readObject();
// 由于obj instanceof List,说明反序列化的结果obj是List集合,所以可以写为
List<Student> stuList = (List<Student>)ois.readObject();
for (Student student : stuList) {
System.out.println(student);
}
ois.close();
}
}
javase:对象输入
最新推荐文章于 2023-07-19 21:05:03 发布