/** * Replaces the file extension of the given path by the given extension * * @param path a valid path (see {@link #isValid(String)}). * @param extension the extension to set. If <code>extension</code> does not * starts with ".", it is automatically added. * @return the given path in which the file extension has been replaced by the * given one. */ public static String replaceExtension(final String path, String extension) { if (!extension.startsWith(".")) extension = "." + extension; return removeExtension(path) + extension; }