// 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.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Ser2 {
    public static class S implements Serializable {
        private static final long serialVersionUID = 1L;
        private String s1;
        private String s2;
        public S() {
            this("", "");
        }
        public S(String s1, String s2) {
            this.s1 = s1;
            this.s2 = s2;
        }
        public String getS1() {
            return s1;
        }
        public String getS2() {
            return s2;
        }
    }
    public static void write(S s) throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("/work/z.ser"));
        oos.writeObject(s);
        oos.close();
    }
    public static void readAndDisplay() throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("/work/z.ser"));
        S s = (S)ois.readObject();
        ois.close();
        System.out.printf("%s %s\n", s.getS1(), s.getS2());
    }
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        write(new S("ABC", "DEF"));
        readAndDisplay();
    }
}
