If the current working directory is /p1, and the path /p1/data does not exist, then what is the result of executing the following code? (Choose all that apply.).
Path path = Paths.get("data"); if(Files.isSameFile(path,Paths.get("/p1/data"))) // x1 Files.createDirectory(path.resolve("info")); // x2
F.
The code compiles without issue, so D and E are incorrect.
The method Files.isSameFile()
first checks to see if the Path values are the same in terms of equals()
.
Since the first path is relative and the second path is absolute, this comparison will return false, forcing isSameFile()
to check for the existence of both paths in the file system.
Since we know /p1/data does not exist, a NoSuchFileException is thrown and F is the correct answer.
A, B, and C are incorrect since an exception is thrown at runtime.