Given the code fragment:
Path source = Paths.get (“/data/december/log.txt”);
Path destination = Paths.get(“/data”);
Files.copy (source, destination);
and assuming that the file /data/december/log.txt is accessible and contains:
10-Dec-2014 – Executed successfully
What is the result?
A.
A file with the name log.txt is created in the /data directory and the content of the /data/december/
log.txt file is copied to it.
B.
The program executes successfully and does NOT change the file system.
C.
A FileNotFoundException is thrown at run time.
D.
A FileAlreadyExistsException is thrown at run time.
The answer should be D since /data is an already existing directory.
Q asks about file int the directory. I think that log.txt file is copied in the data directory from december directory. log.txt exists in december initially and not in data dir.
Unable to solve yet. throws Exception
D
D.
sorry this is wrong. correct answer is A
D is correct “have to put c:\data\log2.txt
Exception in thread “main” java.nio.file.FileAlreadyExistsException: c:\data
at sun.nio.fs.WindowsFileCopy.copy(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.copy(Unknown Source)
at java.nio.file.Files.copy(Unknown Source)
at examen2.Test2.main(Test2.java:135)
D
A the correct answer
Assumption in the question says Executed successfully. which means choice D is not an option.
the first time you run the code it will not give File Already exists, after first run each subsequent run will give file already exists. change dir names and try.