Given two paths, how can I compute the relative path from one to another?
I thought about using split
in fancy ways, but it seems kind of hacky, especially in cases like: "http://foo.com/bar/baz#header"
or "http://foo.com/bar/baz"?param=value
.
An example would be:
String url1 = "http://foo.com/bar/baz";
String url2 = "http://foo.com/bar/qux/quux/corge";
System.out.println(relative(url1, url2)); // -> "../qux/quux/corge"