Resolve absolute URI with relative Path

Viewed 34
Path relative = Paths.get("./index.html");
URI absolute = new URI("https://example.com/");

relative.toUri returns an absolute URI pointing to the file-system. So absolute.resolve(relative.toUri) just ends up returning relative.toUri.

What's the correct way to resolve a URI by a relative Path? And not via toString, which is wont to cause issues on Windows:

absolute.resolve(new URI(relative.toString))
java.net.URISyntaxException: Illegal character in path at index 1: .\index.html
  at java.base/java.net.URI$Parser.fail(URI.java:2974)
  at java.base/java.net.URI$Parser.checkChars(URI.java:3145)
  at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3227)
  at java.base/java.net.URI$Parser.parse(URI.java:3186)
  at java.base/java.net.URI.<init>(URI.java:623)
  ... 40 elided
0 Answers
Related