Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 150

Given the code fragment:

The /scratch/exam/temp.txt file exists. The /scratch/exam/new.txt and /scratch/new.txt files do not exist.

What is the result?

    Correct Answer: B

    The program throws a FileAlreadyExistsException. The first copy operation (Files.copy(currentFile, outputFile)) creates the /scratch/exam/new.txt file by copying the contents of /scratch/exam/temp.txt. However, the second copy operation (Files.copy(outputFile, directory)) attempts to copy /scratch/exam/new.txt to /scratch, which is a directory and already exists. As a result, a FileAlreadyExistsException is thrown because a file with the same name as the directory cannot be created.

Discussion
[Removed]Option: B

I've tried it out and B is correct. If the second statement were absent. The delete would also throw an Exception because the directory is not empty. Correct me if I'm wrong

cathDevOption: B

java.nio.file.FileAlreadyExistsException: \scratch

ASPushkinOption: A

Files.copy(currentFile, outputFile) created new.txt file Files.copy(outputFile, directory) throws java.nio.file.FileAlreadyExistsException because of existing of the /scratch/ folder

d7bb0b2Option: B

Path directory = Paths.get(pathInit+"/scratch/"); try to create a file with the name scratchh but this exist and is a folder so cannot create and throwN already,..

OmnisumemOption: B

Tested: B, ... java.nio.file.FileAlreadyExistsException..