// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.*;
import java.util.*;

public class OOS {
    public static void main(String[] args) throws Exception {
        ArrayList lst1 = new ArrayList();
        lst1.add("a");
        lst1.add("bb");
        lst1.add("ccc");
        System.out.println(lst1);
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("C:\\ser.dat"));
        for(int i = 0; i < lst1.size(); i++) {
            oos.writeObject(lst1.get(i));
        }
        oos.close();
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("C:\\ser.dat"));
        ArrayList lst2 = new ArrayList();
//        while(ois.available() > 0) {
//          lst2.add(ois.readObject());
//        }
        try {
            while(true) {
                lst2.add(ois.readObject());
            }
        } catch(EOFException e) {
            // OK
        }
        ois.close();
        System.out.println(lst2);
    }
}
