1Z0-805 · Question #37
Given the code fragment: public static void main(String[] args) { String source = "d:\\company\\info.txt"; String dest = "d:\\company\\emp\\info.txt"; //insert code fragment here Line } catch…
The correct answer is B. try {Files.copy(Paths.get(source), Paths.get(dest)); D. try {Files.move(Paths.get(source),Paths.get(dest)). See the full explanation below for the reasoning.
Question
Given the code fragment:
public static void main(String[] args) { String source = "d:\company\info.txt"; String dest = "d:\company\emp\info.txt"; //insert code fragment here Line ** } catch (IOException e) { System.err.println ("Caught IOException: " + e.getmessage(); Oracle 1Z0-805 Exam } } Which two try statements, when inserted at line **, enable the code to successfully move the file info.txt to the destination directory, even if a file by the same name already exists in the destination directory?
Options
- Atry {FileChannel in = new FileInputStream(source).getChannel(); FileChannel out = new FileOutput
- Btry {Files.copy(Paths.get(source), Paths.get(dest));
- Ctry {Files.copy(Paths.get(source), Paths.get(dest));
- Dtry {Files.move(Paths.get(source),Paths.get(dest));
- Etry {BufferedReader br = Files.newBufferedReader(Paths.get(source), Charset.forName ("UTF- 8"));
How the community answered
(24 responses)- A13% (3)
- B75% (18)
- C4% (1)
- E8% (2)
Community Discussion
No community discussion yet for this question.