code: public static void writeObjectToFile(File file, Object object) throws IOException {
      FileOutputStream fs = new FileOutputStream(file);
      ObjectOutputStream os = new ObjectOutputStream(fs);
      os.writeObject(object);
      os.close();
    }
docs: Writes a single object to a file.
  @param file The <code>File</code> to write to.
  @param object The <code>Object</code> to write.
  @throws IOException If the file could not be written.