p1.normalize() = ''personal\\readme.txt"
and the answer is "p3=..\index.html".
It is not correct. The correct is "p3=..\..\..\..\index.html"
Code: Select all
Path p1 = Paths.get("personal\\.\\photos\\..\\readme.txt");
Path p2 = Paths.get("personal\\index.html");
Path p3 = p1.relativize(p2);
System.out.println("p3=" + p3); // output: p3=..\..\..\..\index.html
System.out.println("p=" + p1.resolve(p3).normalize()); // output: p=..\..\index.html
I do not know how much you can trust the following explanation, but people are talking about a bug in Path#relativize https://stackoverflow.com/questions/377 ... 2#37749932 (mysterious bug JDK-6925169)
So, in my opinion, there is either a bug, or poor documentation. And the question is about edge case, with not correct explanation of answer.The Path implementation does not handle . and .. components correctly in relativize, but treats them like any other path component.