5、mport java.io.ObjectOutputStream;import java.io.Serializable;public class Box implements Serializable {1.private static final long serialVersionUID = 1L;2.private int width;3.private int height;4.private String name;5.public static void main(String[] args) {6.try {7.Box myBox = new Box(
6、);8.myBox.setWidth(50);9.myBox.setHeight(30);10.myBox.setName(“雕戈”);11.FileOutputStream fs = new FileOutputStream(“serializableObject.txt”);12.ObjectOutputStream os = new ObjectOutputStream(fs);13.os.writeObject(myBox);14.os.close();15.fs.close();16.} catch (Exception ex) {17.ex.printSt
7、ackTrace();18.}19.try {20.FileInputStream fis = new FileInputStream(“serializableObject.txt”);21.ObjectInputStream ois = new ObjectInputStream(fis);22.Box box = (Box) ois.readObject();23.System.out.println(box.getWidth());24.System.out.println(box.getHeight());25.System.out.pri