import java.io.*; class Moo implements Serializable { int v; public Moo() {} public Moo(int v) { this.v = v; } public void print(){ System.out.println("v = " + Integer.toHexString(v)); } } public class MooMain { public static void dumpToFile(Moo moo, String name){ try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(name)); oos.writeObject(moo); } catch(IOException ie){ ie.printStackTrace(); } } public static Moo restoreFromFile(String name){ try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(name)); return (Moo)ois.readObject(); } catch(IOException ie){ ie.printStackTrace(); } catch(ClassNotFoundException cfe){ cfe.printStackTrace(); } return null; } public static void main(String[] args){ Moo moo = new Moo(0x12345678); MooMain.dumpToFile(moo, "moo.txt"); Moo moo2 = MooMain.restoreFromFile("moo.txt"); moo2.print(); } }