package HeadFirstJava;
import java.io.*;
@SuppressWarnings("serial")
public class Box implements Serializable {
@SuppressWarnings("unused")
private int width;
@SuppressWarnings("unused")
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();
}
}
}
serialization DEMO
最新推荐文章于 2021-01-29 17:12:23 发布