Ejemplo n.º 1
0
 public static void loadShapes(File fileToLoad, ShapeControl shapeControl) throws Exception {
   try (FileInputStream fileIn = new FileInputStream(fileToLoad)) {
     try (ObjectInputStream in = new ObjectInputStream(fileIn)) {
       Shape[] newShapes = (Shape[]) in.readObject();
       shapeControl.loadShapes(newShapes);
     }
   }
 }
Ejemplo n.º 2
0
  public static void saveShapes(File file, ShapeControl shapeControl) throws Exception {
    // http://www.tutorialspoint.com/java/java_serialization.htm

    if (file == null) throw new Exception("No file chosen");

    file.createNewFile();
    try (FileOutputStream fileOut = new FileOutputStream(file)) {
      try (ObjectOutputStream out = new ObjectOutputStream(fileOut)) {
        out.writeObject(shapeControl.getShapes());
      }
    }
  }