import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class User implements Serializable{
private static final long serialVersionUID =1;
private String name;
private int age;
public User(String name,int age)
{
this.name =name;
this.age =age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public static void main(String args[])
{
User u = new User("zhangshan",18);
try
{
FileOutputStream ofs = new FileOutputStream("user.bin");
ObjectOutputStream oos = new ObjectOutputStream(ofs);
oos.writeObject(u);
oos.close();
}
catch (Exception e)
{
System.out.println("Serial object error");
}
try
{
FileInputStream ifs = new FileInputStream("user.bin");
ObjectInputStream ios = new ObjectInputStream(ifs);
User au = (User)ios.readObject();
ios.close();
System.out.println(au.age);
}
catch (Exception e)
{
System.out.println("UnSerial object error");
}
}
}
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- awee.cn 版权所有 湘ICP备2023022495号-5
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务