nerdexam
Oracle

1Z0-819 · Question #62

Given try { // line 1 lines.map(l -> l.toUpperCase()) .forEach (line -> { try { Files.write(Paths.get("outputfile_to_path"), line.getBytes(),StandardOpenOption.CREATE); } catch (IOException e) {…

The correct answer is A. A. var lines = Files.lines(Paths.get(INPUT_FILE_NAME)). See the full explanation below for the reasoning.

Question

Given try { // line 1 lines.map(l -> l.toUpperCase()) .forEach (line -> { try { Files.write(Paths.get("outputfile_to_path"), line.getBytes(),StandardOpenOption.CREATE); } catch (IOException e) { e.printStackTrace(); } }); } catch (IOException e) { e.printStackTrace(); } You want to obtain the Stream object on reading the file. Which code inserted on line 1 will accomplish this?

Options

  • AA. var lines = Files.lines(Paths.get(INPUT_FILE_NAME));
  • BB. Stream<String> files = Files.lines(Paths.get(INPUT_FILE_NAME));
  • CC. var lines = Files.readAllLines(Paths.get(INPUT_FILE_NAME));
  • DD. Stream<String> lines = Files.lines(INPUT_FILE_NAME);

How the community answered

(43 responses)
  • A
    81% (35)
  • B
    5% (2)
  • C
    12% (5)
  • D
    2% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice