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?
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?
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.
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
java.nio.file.FileAlreadyExistsException: \scratch
Files.copy(currentFile, outputFile) created new.txt file Files.copy(outputFile, directory) throws java.nio.file.FileAlreadyExistsException because of existing of the /scratch/ folder
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,..
Tested: B, ... java.nio.file.FileAlreadyExistsException..