What is the result?

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?

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.



Leave a Reply 11

Your email address will not be published. Required fields are marked *


DG

DG

The answer should be D since /data is an already existing directory.

smh

smh

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.

smh

smh

Unable to solve yet. throws Exception

smh

smh

D.

smh

smh

sorry this is wrong. correct answer is A

Berti John

Berti John

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)

smh

smh

A the correct answer

smh

smh

Assumption in the question says Executed successfully. which means choice D is not an option.

smh

smh

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.