import java.io.Serializable;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
public class Java_ObjIptSamFun {
public static void main(String[] args) {
try
{
FileInputStream f =new FileInputStream("C:\\a.txt");
ObjectInputStream in= new ObjectInputStream(f);
//使用ObjectInputStream对象进行反序列化
Customer customer =(Customer) in.readObject();
System.out.println(customer.getName());
System.out.println(customer.getAge());
in.close();
f.close();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
class Customer implements Serializable
{
private static final long serialVersionUID =1L;
private String name;
private int age;
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public Customer(String name,int age)
{
this.name=name;
this.age=age;
}
public String toString()
{
return "name="+ name +",age="+age;
}