package com.ff20240616;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class StudentObjectStream {
public static void main(String[] args) throws IOException, ClassNotFoundException {
String path ="D:\\idea-workspeace\\hello\\ff20240616\\resource\\student.dat";
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(path,true));
Student s1= new Student("貂蝉","女",18,"中国");
Student s2=new Student("武建军","女",99,"日本");
List<Student> list=new ArrayList<>();
list.add(s1);
list.add(s2);
out.writeObject(list);
out.close();
ObjectInputStream in = new ObjectInputStream(new FileInputStream(path));
List<Student> ls= (List<Student>) in.readObject();
for(Student s:ls){
System.out.println(s);
}
}
}
JAVA
最新推荐文章于 2024-08-15 19:51:06 发布