code: public static File getTempFileFor(File file) {
      File parent = file.getParentFile();
      String name = file.getName();
      File result;
      int index = 0;
      do {
        result = new File(parent, name + "_" + index++);
      }
      while (result.exists());
      return result;
    }
docs: Find a non-existing file in the same directory using the same name as prefix.
  
  @param file file used for the name and location (it is not read or written).
  @return a non-existing file in the same directory using the same name as prefix.