nerdexam
Oracle

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…

NIO.2

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

1Z0-804 question #57 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)
  • A
    2% (1)
  • B
    4% (2)
  • C
    78% (36)
  • D
    15% (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

#Files.move#Files.copy#try-with-resources#StandardCopyOption

Community Discussion

No community discussion yet for this question.

Full 1Z0-804 Practice