code: public static File nonDuplicateFile(File dir, String name){
          int count = 1;
          File outputFile = new File(dir, name);
          while(outputFile.exists()){
              String cleanName = cleanFilename(name);
              int extIndex = name.lastIndexOf(".");
              String extension = "";
              if(extIndex != -1) {
                  extension = name.substring(extIndex + 1);
              }
  
              String revisedFileName = String.format(Locale.US, "%s(%d).%s", cleanName, count, extension);
              outputFile = new File(dir, revisedFileName);
              count++;
          }
  
          return outputFile;
      }
docs: Create a non duplicate file in the given directory with the given name, appending a duplicate
  counter to the end of the name but before the extension like: `some_file(1).jpg`
  
  @param dir The parent directory of the desired file
  @param name The desired name of the file
  @return The non-duplicate file