code: public static String renameIfExists(String path) {
      File file = new File(path);
      if (file.exists() && file.isFile()) {
        int index = file.getName().lastIndexOf(".");
        String name = file.getName().substring(0, index);
        String suffix = index == -1 ? "" : file.getName().substring(index);
        int i = 1;
        String newName;
        do {
          newName = name + "(" + i + ")" + suffix;
          i++;
        }
        while (existsFile(file.getParent() + File.separator + newName));
        return newName;
      }
      return file.getName();
    }
docs: 判断文件存在是重命名