对象反序列化只能获取一个对象,如果要存储多个对象呢?
对象的集合也是对象,把对象放到一个集合里,再把集合当成是一个对象进行序列化和反序列化即可;
import java.io.*;
import java.util.ArrayList;
public class PrintWriterDemo01 {
private static class Student implements Serializable {
public static final long serialVersionUID = 98L;
String name;
int age;
transient String address;
public Student(String name, int age, String address) {
this.name = name;
this.age = age;
this.address = address;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", age=" + age +
", address='" + address + '\'' +
'}&#