code: public static void writePropertiesToFile(Properties prop, 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)) {
        prop.store(fos, "");
        fos.getChannel().force(true);
      }
      atomicMove(temp, file);
      LOG.debug("Atomically moved {} to {}", temp, file);
    }
docs: Atomically writes properties to a file.
  
  This method writes properties to a file by first writing it to a
  temporary file and then atomically moving it to the destination,
  overwriting the destination file if it already exists.
  
  @param prop a Properties object to write.
  @param file file to write the value to.
  @throws IOException if an I/O error occurs.