Java SE 8 Programmer II — Question 54

Given that /green.txt and /colors/yellow.txt are accessible, and the code fragment:
Path source = Paths.get("/green.txt);
Path target = Paths.get("/colors/yellow.txt);
Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
Files.delete(source);
Which statement is true?

Answer options

Correct answer: B

Explanation

The correct answer is B because the Files.move method with StandardCopyOption.ATOMIC_MOVE will attempt to overwrite yellow.txt with green.txt's content, which results in an exception since yellow.txt already exists. Options A and C are incorrect as they misinterpret the file operations, and D is incorrect because the exception does not relate to the file already existing in the context of an atomic move.