import java.io.*;
public class Box implements Serializable
{
private int width;
private int height;
public void setWidth(int w)
{
width=w;
}
public void setHeight(int h)
{
height=h;
}
public static void main(String [] args)
{
Box myBox=new Box();
myBox.setWidth(50);
myBox.setHeight(20);
try
{
FileOutputStream fs=new FileOutputStream("foo.ser");
ObjectOutputStream os=new ObjectOutputStream(fs);
os.writeObject(myBox);
os.close();
}catch(Exception ex){ex.printStackTrace();}
}
}
Serializable的实例
最新推荐文章于 2023-01-12 12:11:18 发布