I have seen that yes, in fact it even has this in the API
For example, if this path is "/a/b" and the given path is "/a/x" then the resulting relative path may be "../x"
I just don't understand why it would be .. and not .
All dealings with relative paths in the past have had . to mean current directory and .. as one level up
Or is it in fact saying for example if we just take
This would give
Relatively it is one level up from Java.java therefore the path is "../Java.class". Does that make sense?
posted 5 years ago
Ok I have worked it out, I had to break it up into bullet points to understand it though. Here are some of my notes if it helps someone else
Path relativize(Path other)
- This method attempts to construct a relative path that when resolved against this path, yields a path that locates the same file as the given path
- Where this path and the given path do not have a root component, then a relative path can be constructed
- A relative path cannot be constructed if only one of the paths have a root component
- If this path and the given path are equal then an empty path is returned
- /a/b -> /a/b/c/d = c/d
- a/b -> a/b/c/d = c/d
- /a/b/c/d -> a/b = IllegalArgumentException
- /a/b/c/d -> /a/b = ../..
- /a/b -> /a/b = ""
- /a/b -> /a/c = ../c
- /x/d/g/a/b -> /a/b = ../../../../../a/b
The first person to drink cow's milk. That started off as a dare from this tiny ad: