Assuming the current working directory is /2D, what is the expected output of executing the following code snippet?
Path w1 = Paths .get("../shape/.././rectangle..") .toAbsolutePath().normalize(); System.out.print(w1.resolve("square.txt"));
C.
The toAbsolutePath()
combines the current working directory and relative path to form a /2D/../shape/.././rectangle.. path.
The normalize()
method removes the path symbols and leaves a /rectangle.. value.
Note that the last double period ( ..) is not removed because it is part of a path name and not interpreted as a path symbol.
The result is then appended with square.txt and we are left with /rectangle../square.txt, making Option C the correct answer.