I agree that we use relativize method to generate a relative path. No disagreement here.p1.relativize("c:\\temp\\text2.txt");
This is wrong for two reasons -
1. relativize method does not take a String as an argument. It takes a Path object.
2. relativize method is meant to convert an absolute path into a relative path. But here, we want to convert a relative path to an absolute path. For example, p2 = p1.relativize(Paths.get("c:\\temp\\text2.txt")); will produce "..\text2.txt".
In the above quote, however, you said something confusing:
"But here, we want to convert a relative path to an absolute path."
Did you mean to say the following?
To tackle the problem in the question, we need to generate an absolute path as a result. We need to consume a relative path and use it with the given absolute path (p1) to generate such an absolute path.
Is that what you mean to say when you said "But here, we want to convert a relative path to an absolute path.".
Thanks.
Schmichael