程序如下:
import java.io.*;
class Person implements Serializable
{
private String name;
private int age;
public Person(String name,int age)
{
this.name=name;
this.age=age;
}
public void print()
{
System.out.println("姓名:"+name+"/n年龄:"+age);
}
}
class ObjectOutputTest
{
public static void main(String[] args)throws Exception
{
Person p=new Person("三生石",23);
FileOutputStream fos=new FileOutputStream("d:\\person.txt");
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(p);
fos.close();
oos.close();
}
}
运行结果:
为什么是乱码呢?
|