code: public static void writeLongToFile(long value, File file) throws IOException {
      // Create a temp file in the same directory as the file parameter.
      File temp = File.createTempFile(file.getName(), null,
                                      file.getAbsoluteFile().getParentFile());
      try (FileOutputStream fos = new FileOutputStream(temp);
           OutputStreamWriter os =
            new OutputStreamWriter(fos, Charset.forName("UTF-8"));
           PrintWriter pw = new PrintWriter(os)) {
        pw.print(Long.toString(value));
        fos.getChannel().force(true);
      }
      atomicMove(temp, file);
      LOG.debug("Atomically moved {} to {}", temp, file);
    }
docs: Atomically writes a long integer to a file.
  
  This method writes a long integer to a file by first writing the long
  integer to a temporary file and then atomically moving it to the
  destination, overwriting the destination file if it already exists.
  
  @param value a long integer value to write.
  @param file file to write the value to.
  @throws IOException if an I/O error occurs.