写:
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);}
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);}
如(同一文件中):
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
{}