1Z0-804 · Question #57
Given the code fragment: Which two try statements, when inserted at line ***, enable the code to successfully move the file info.txt to thedestination directory, even if a file by the same name…
The correct answer is C. try ( Files.copy(Paths.get(source), E. try(BufferedReader br = Files.newBufferedReader(Paths.get(source). A: copies only, don't move operation B,C,D (no try-with-resource !) syntax change to: try { ... B: throws FileAlreadyExistsException C: correct if syntax change to : StandardCopyOption.REPLACE_EXISTING (before REPLACE_Existing) D: throws FileAlreadyExistsException E: works…
Question
Given the code fragment:
Which two try statements, when inserted at line ***, enable the code to successfully move the file info.txt to thedestination directory, even if a file by the same name already exists in the destination directory?
Exhibit
Options
- Atry (FileChannel in = new FileInputStream (source). getChannel();
- Btry ( Files.copy(Paths.get(source),Paths.get(dest));
- Ctry ( Files.copy(Paths.get(source),
- Dtry (Files.move(Paths.get(source),Paths.get(dest));
- Etry(BufferedReader br = Files.newBufferedReader(Paths.get(source),
How the community answered
(46 responses)- A2% (1)
- B4% (2)
- C78% (36)
- D15% (7)
Explanation
A: copies only, don't move operation B,C,D (no try-with-resource !) syntax change to: try { ... B: throws FileAlreadyExistsException C: correct if syntax change to : StandardCopyOption.REPLACE_EXISTING (before REPLACE_Existing) D: throws FileAlreadyExistsException E: works properly if the sourcefile has the correct format, utf-8 here (else throws MalformedInputException) AND syntax is corrected to: try ( BufferedReader br = Files.newBufferedReader(Paths.get(source), Charset.forName("UTF- BufferedWriter bw = Files.newBufferedWriter(Paths.get(dest), Charset.forName("UTF-8)); ){ String record = "";
Topics
Community Discussion
No community discussion yet for this question.
