Point.java

import java.io.*;
public class Point implements Serializable {
  private int x;
  private int y;
  public Point(int x, int y) {
    this.x = x;
    this.y = y;
  }
  public String toString() {
    return "(" + x + "," + y + ")";
  }
  public static void main(String[] args)
    throws IOException, ClassNotFoundException { 
    Point a = new Point(1,2);
    File f = File.createTempFile("tempFile","test");
    f.deleteOnExit(); // Effacer le fichier à la fin du programme
    ObjectOutputStream out = 
      new ObjectOutputStream(new FileOutputStream(f));
    out.writeObject(a); // Écriture de l'objet
    out.close();
    ObjectInputStream in = 
      new ObjectInputStream(new FileInputStream(f));
    Point aPrime = (Point) in.readObject(); // Lecture de l'objet
    in.close();
    System.out.println("a = " + a);
    System.out.println("aPrime  = " + aPrime);
    System.out.println("Egalité = " + (a == aPrime));
  }
}