62,615
社区成员
发帖
与我相关
我的任务
分享
import java.io.*;
public class Test {
/**
* @param args
* @throws IOException
* @throws FileNotFoundException
* @throws ClassNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
// TODO Auto-generated method stub
Man man=new Man("Kobe",28);
ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream(new File("D:/Man.txt")) );
out.writeObject(man);
out.close();
ObjectInputStream in=new ObjectInputStream(new FileInputStream(new File("D:/Man.txt")) );
man=(Man)in.readObject();
in.close();
System.out.println(man);
}
}
class Man implements Serializable
{
public Man(String name,int age)
{
this.name=name;
this.age=age;
}
private int age;
private String name="";
@Override
public String toString() {
return "Man [age=" + age + ", name=" + name + "]";
}
}