package be.crydust.tokenreplacer;

import java.nio.file.Path;
import java.util.Objects;

/**
 *
 * @author kristof
 */
public final class FileExtensionUtil {

    private FileExtensionUtil() {
    }

    public static Path replaceExtension(Path path, String newExtension) {
        Objects.requireNonNull(path);
        Objects.requireNonNull(newExtension);
        Path folder = path.getParent();
        String originalFileName = path.getFileName().toString();
        if (!originalFileName.contains(".")) {
            throw new IllegalArgumentException("path has no extension");
        }
        final String dot;
        if (newExtension.isEmpty() || newExtension.startsWith(".")) {
            dot = "";
        } else {
            dot = ".";
        }
        String newFileName = originalFileName.replaceFirst("\\.\\w+$", dot + newExtension);
        return folder.resolve(newFileName);
    }
}

@@ -355,48 +355,8 @@
 n);%0A
-        Path folder = path.getParent();%0A
     
@@ -825,22 +825,20 @@
 urn 
-folder
+path
 .resolve
 (new
@@ -833,16 +833,23 @@
 .resolve
+Sibling
 (newFile

use resolvesibling instead of doing that manually