Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 120

Assume customers.txt is accessible and contains multiple lines.

Which code fragment prints the contents of the customers.txt file?

    Correct Answer: D

    To print the contents of a file line by line in Java, you can use the Files.lines(path) method, which returns a Stream of String lines. Therefore, the code fragment 'Stream<String> lines = Files.lines (Paths.get ("customers.txt")); lines.forEach( c -> System.out.println(c));' is correct because it correctly reads each line of the file and prints it. The other options use incorrect methods or have syntax errors.

Discussion
jduarteOption: D

the correct answer is D

asdfjhfgjuaDCVOption: D

D is the answer

steefaandOption: D

D is correct.

duydnOption: D

Files.lines(path) return a Stream so D is correct

MahdiHamdiiOption: D

The correct answer is D!!.