其实对象的序列化就是对象的保存(我认为)
下面有两个程序,一个是保存一个对象,一个是读出这个对象
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.awt.event.*;
/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2002
 * Company:
 * @author
 * @version 1.0
 */public class SerialSample1 extends JFrame {    public SerialSample1(String title) {
        super(title);
    }
    public static void main(String[] args) {
        SerialSample1 frame1 = new SerialSample1("SerialSample1");
        frame1.init();
        frame1.setSize(400,400);
        frame1.setVisible(true);
        frame1.addWindowListener(frame1.a);
    }
    WindowClose a = new WindowClose();
    class WindowClose extends WindowAdapter{
        public void windowClosing(WindowEvent e){
            System.exit(0);
        }
    }
    DrawPicture drawArea = new DrawPicture();
    JButton
        saveButton = new JButton("Save Picture"),
        clearButton = new JButton("Clear Picture");
    ArrayList picture;
    ActionListener saveL = new ActionListener(){
        public void actionPerformed(ActionEvent e){
            try{
                ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("objectFile"));
                out.writeObject(picture);
                out.flush();
                out.close();
            }catch(Exception ex){
            }
        }
    };
    ActionListener clearL = new ActionListener(){
        public void actionPerformed(ActionEvent e){
            picture = new ArrayList();
            repaint();
        }
    };
    MouseAdapter drawL = new MouseAdapter(){
        public void mouseClicked(MouseEvent e){
            Point p = new Point(e.getX(),e.getY());
            picture.add(p);
            repaint();
        }
    };
    public void init(){
        picture = new ArrayList();
        saveButton.addActionListener(saveL);
        clearButton.addActionListener(clearL);
        Container cp = getContentPane();
        cp.setLayout(new FlowLayout());
        cp.add(saveButton);
        cp.add(clearButton);
        cp.add(drawArea);
        File file = new File("c:"+System.getProperty("file.separator")+"dlr.txt");
        System.out.println(file.getPath());
        System.out.println(file.exists());
        drawArea.addMouseListener(drawL);
    }
    class DrawPicture extends JTextArea{
        DrawPicture(){
            super("Draw circles",10,20);
            repaint();
        }
        public void paintComponent(Graphics g){
            super.paintComponent(g);
            g.setColor(Color.blue);
            int i=0;
            while(i<picture.size()){
                Point p0=(Point)(picture.get(i++));
                int x=p0.x;
                int y=p0.y;
                g.drawOval(x,y,50,50);
            }
        }
    }
}
//恢复对象
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.tree.DefaultMutableTreeNode;
/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2002
 * Company:
 * @author
 * @version 1.0
 */public class DeserialSample1 extends JFrame {    public DeserialSample1(String title) {
        super(title);
    }
    public static void main(String[] args) {
        DeserialSample1 frame1 = new DeserialSample1("DeSerialSample1");
        frame1.init();
        frame1.setSize(400,400);
        frame1.setVisible(true);
        frame1.addWindowListener(frame1.a);
    }
    WindowClose a = new WindowClose();
    class WindowClose extends WindowAdapter{
        public void windowClosing(WindowEvent e){
            System.exit(0);
        }
    }
    DrawPicture drawArea = new DrawPicture();
    ArrayList picture;
    JButton loadButton = new JButton("Load Picture");
    MouseAdapter drawL = new MouseAdapter(){
        public void mouseClicked(MouseEvent e){
            Point p = new Point(e.getX(),e.getY());
            picture.add(p);
            repaint();
        }
    };
    ActionListener restoreL = new ActionListener(){
        public void actionPerformed(ActionEvent e){
            try{
                System.out.println("ok");
                ObjectInputStream in = new ObjectInputStream(new FileInputStream("objectFile"));
                picture = (ArrayList)in.readObject();
                in.close();
                repaint();
            }catch(Exception e1){
            }
        }
    };
    public void init(){
        picture= new ArrayList();
        loadButton.addActionListener(restoreL);
        Container cp =getContentPane();
        cp.setLayout(new FlowLayout());
        cp.add(loadButton);
        cp.add(drawArea);
        drawArea.addMouseListener(drawL);
    }    class DrawPicture extends JTextArea{
        DrawPicture(){
            super("Draw circles",10,20);
            repaint();
        }
        public void paintComponent(Graphics g){
            super.paintComponent(g);
            g.setColor(Color.blue);
            int i=0;
            while(i<picture.size()){
                Point p0=(Point)(picture.get(i++));
                int x=p0.x;
                int y=p0.y;
                g.drawOval(x,y,50,50);
            }
        }
    }
}