Path p1 = Paths.get(\"/Users/jack/Documents/text1.txt\");
Path p2 = Paths.get(\"/Users/jack/text2.txt\");
Path result1 = p1.resolve(p2);
Path result2 = p1.relativize(p2)
resolve()
: Joins two paths.
relativize ()
: construct a path from one location in the file system to another location.
Output explanation:
result1: /Users/jack/text2.txt
: because you passed in an absolute path, resolve()
returns the passed in the path as is if it is an absolute path.
result2: ../../text2.txt
: to get to /Users/jack/text2.txt
from /Users/jack/Documents/text1.txt"
you need to to go two levels up, and then just select `text2.txt file.