Dear Forum,
In preparing for my
java 8 OCPJP exam, I am playing with Path.relativize().
I know other related questions have been asked.
I have read Path.relativize() javadoc, I have seen examples.
But I still cannot get my head around the following scenario(I use Linux, apologies to window users):
My current working directory for my program is: /home/userspace/workspace/java8/
I have two files:
/home/userspace/workspace/java8/zoo.txt
and
/home/userspace/temp/delete/dictionary.txt
I also have the following program
testing Path.relativize():
The output is:
relativePathToZoo.relativize(relativePathToDictionary): ../../../temp/delete/dictionary.txt
relativePathToZoo.relativize(relativePathToDictionary).toAbsolutePath(): /home/userspace/workspace/java8/../../../temp/delete/dictionary.txt
relativePathToZoo.relativize(relativePathToDictionary).toAbsolutePath().normalize(): /home/temp/delete/dictionary.txt
relativePathToDictionary.relativize(relativePathToZoo): ../../../../../zoo.txt
relativePathToDictionary.relativize(relativePathToZoo).toAbsolutePath().normalize(): /zoo.txt
My question, the bit I cannot understand is:
Why does relativePathToDictionary.relativize(relativePathToZoo) output ../../../../../zoo.txt??
When normalized, it would make you think that zoo.txt lives in the root directory.
How does relativize() work out such a deep path?
I understand that relativize() works in relation to the current working directory, so it adds
..
to every path. But I am cannot understand, how it worked out the path to zoo.txt in relation to dictionary.txt.
Thanks in advance,
Lucas