code: public static File swapExtension(final File f, final String newExtension) {
      checkNotNull(f);
      checkNotNull(newExtension);
      Preconditions.checkArgument(!f.isDirectory());
  
      final String absolutePath = f.getAbsolutePath();
      final int dotIndex = absolutePath.lastIndexOf(".");
      String basePath;
  
      if (dotIndex >= 0) {
        basePath = absolutePath.substring(0, dotIndex);
      } else {
        basePath = absolutePath;
      }
  
      return new File(String.format("%s.%s", basePath, newExtension));
    }
docs: Returns another file just like the input but with a different extension. If the input file has
  an extension (a suffix beginning with "."), everything after the . is replaced with
  newExtension. Otherwise, a newExtension is appended to the filename and a new File is returned.
  Note that unless you want double .s, newExtension should not begin with a .