public class Main {
public static void main(String[] args) {
try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("person.dat", false))) {
Person p = new Person("Sam", 33, 178, true);
Person p2 = new Person("John", 40, 165, false);
oos.writeObject(p);
oos.writeObject(p2);
} catch(Exception ex) {
System.out.println(ex.getMessage());
}
try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream("person.dat"))) {
Person p = (Person) ois.readObject();
System.out.println(p.getName());
System.out.println(p.getAge());
System.out.println(p.getHeight());
System.out.println(p.getMarried());
Person p2 = (Person) ois.readObject();
System.out.println(p2.getName());
System.out.println(p2.getAge());
System.out.println(p2.getHeight());
System.out.println(p2.getMarried());
} catch (Exception e) {
e.fillInStackTrace();
}
}
}