import java.io.*; public class TestSingle { public static void main(String[] args) throws Exception { if ("in".equals(args[0])) { ObjectInputStream in = new ObjectInputStream(new FileInputStream(args[1])); Single s = (Single) in.readObject(); in.close(); System.out.println("same ? " + (s == Single.getInstance())); } else { ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream(args[1])); o.writeObject(Single.getInstance()); o.close(); System.out.println("written " + args[1]); } } }