code: public static String resuffix (File file, String ext, String newext)
      {
          String path = file.getPath();
          if (path.endsWith(ext)) {
              path = path.substring(0, path.length()-ext.length());
          }
          return path + newext;
      }
docs: Replaces <code>ext</code> with the supplied new extention if the
  supplied file path ends in <code>ext</code>. Otherwise the new
  extension is appended to the whole existing file path.