code: public static void renamePath(FileSystem fs, Path oldName, Path newName, boolean overwrite) throws IOException {
      if (!fs.exists(oldName)) {
        throw new FileNotFoundException(String.format("Failed to rename %s to %s: src not found", oldName, newName));
      }
      if (fs.exists(newName)) {
        if (overwrite) {
          HadoopUtils.moveToTrash(fs, newName);
        } else {
          throw new FileAlreadyExistsException(
              String.format("Failed to rename %s to %s: dst already exists", oldName, newName));
        }
      }
      if (!fs.rename(oldName, newName)) {
        throw new IOException(String.format("Failed to rename %s to %s", oldName, newName));
      }
    }
docs: A wrapper around {@link FileSystem#rename(Path, Path)} which throws {@link IOException} if
  {@link FileSystem#rename(Path, Path)} returns False.