Java SE 8 Programmer II — Question 46

/green.txt and /colors/yellow.txt are accessible, and the code fragment:

Given that -
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?
green.txt file content is replaced by the yellow.txt file content and the yellow.txt file is deleted.

Answer options

Correct answer: A

Explanation

The correct answer is A because the code attempts to move green.txt to a location where yellow.txt already exists, leading to a FileAlreadyExistsException. Options B and C are incorrect as they do not accurately describe the result of the operation, and D is just a repeat of A.