Java SE 11 Developer — Question 36

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?

Answer options

Correct answer: C

Explanation

The correct answer is C because the Files.move method transfers the file to the destination directory and deletes the original file. Option A is incorrect as there is no existing file conflict in this scenario, while option B is wrong because the source file is successfully moved before the delete operation. Option D is inaccurate since the file is not renamed; it is moved.