Question 1
Given the code fragment:
Path currentFile = Paths.get(“/scratch/exam/temp.txt”);
Path outputFile = Paths get(“/scratch/exam/new.txt”);
Path directory = Paths.get(“/scratch/”); Files.copy(currentFile, outputFile);
Files.copy(outputFile, directory);
Files.delete (outputFile);
The /scratch/exam/temp.txt file exists. The /scratch/exam/new.txt and /scratch/new.txt files do not exist.
What is the result?
/scratch/exam/new.txt and /scratch/new.txt are deleted.
The program throws a FileaAlreadyExistsException.
The program throws a NoSuchFileException.
A copy of /scratch/exam/new.txt exists in the /scratch directory and /scratch/exam/new.txt is deleted.
Correct answer: C