public class student implements Serializable{
String name;
int no;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public static void main(String[] args) throws IOException, ClassNotFoundException {
// TODO 自动生成的方法存根
student stu1=new student();
stu1.setName("郭靖");
stu1.setNo(11);
File file=new File("D:/testfile/ojb.txt");
FileOutputStream fos=new FileOutputStream(file);
ObjectOutputStream objout=new ObjectOutputStream(fos);
objout.writeObject(stu1);
objout.close();
FileInputStream fis=new FileInputStream(file);
ObjectInputStream objin=new ObjectInputStream(fis);
student stunew=(student)objin.readObject();
System.out.println(stunew.name+" " +stunew.no);
objin.close();
}
}
对象流
最新推荐文章于 2022-08-16 21:08:42 发布