code: public static File findFreeFile(File file){
          if(!file.exists())
              return file;
  
          String parts[] = split(file.getName());
          String pattern = parts[1]==null ? parts[0]+"${i}" : parts[0]+"${i}."+parts[1];
          return findFreeFile(file.getParentFile(), pattern, true);
      }
docs: if file doesn't exist, it returns the same file. otherwize, it will find free
  file as follows:
  
  if given file name is test.txt, then it searches for non existing file in order:
  test2.txt, test3.txt, test4.txt and so on
  
  if given file name is test(i,e with no extension), then it searches for non existing file in order:
  test2, test3, test4 and so on