Exam 1z0-816 All QuestionsBrowse all questions from this exam
Question 37

Given the code fragment:

Path source = Paths.get(“/repo/a/a.txt”);

Path destination = Paths.get(“/repo”);

Files.move(source, destination); // line 1

Files.delete (source);// line 2 -

Assuming the source file and destination folder exist, what Is the result?

    Correct Answer: B

    The code attempts to move the file /repo/a/a.txt to the /repo directory. However, the move operation will not succeed because the destination is a directory, not a file. In such cases, the source file would not be deleted, and attempting to delete it with Files.delete(source) on line 2 will throw a java.nio.file.NoSuchFileException since the file would not exist at the original location anymore.

Discussion
Sa16253748596Option: A

A is true