code: public static void writeFile(File file, long val) throws IOException {
      AtomicFileOutputStream fos = new AtomicFileOutputStream(file);
      try {
        fos.write(String.valueOf(val).getBytes(Charsets.UTF_8));
        fos.write('\n');
        fos.close();
        fos = null;
      } finally {
        if (fos != null) {
          fos.abort();        
        }
      }
    }
docs: Atomically write the given value to the given file, including fsyncing.
  
  @param file destination file
  @param val value to write
  @throws IOException if the file cannot be written