写:
try{ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(filename));
oos.writeObject(new custom());
oos.flush();
oos.close();
}catch(IOException ioe){System.out.println(ioe);}读(还原)
try{
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filename));
custom s = (custom)ois.readObject();
ois.close();
}catch(Exception e){System.out.println(e);}

解决方案 »

  1.   

    可以直接写在同一个文件中,也可以分开来。
    如(同一文件中):
    import java.io.*;public class testCustom
    {    public testCustom()
        {
            try{
                ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("c:\\dat.idl"));
                oos.writeObject(new custom());
                oos.flush();
                oos.close();
                }catch(IOException ioe){System.out.println(ioe);}    }
        public static void main(String[] args)
        {
            testCustom testCustom1 = new testCustom();
        }
    }
    class custom implements Serializable
    {}