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

The data.doc, data.txt and data.xml files are accessible and contain text.

Given the code fragment:

Stream paths = Stream.of (Paths. get("data.doc"),

Paths. get("data.txt"),

Paths. get("data.xml"));

paths.filter(s-> s.toString().contains("data")).forEach(

s -> {

try {

Files.readAllLines(s)

.stream()

.forEach(System.out::println); //line n1

} catch (IOException e) {

System.out.println("Exception");

}

}

);

What is the result?

    Correct Answer: D

    The program prints the content of the three files. The Stream.of method creates a Stream containing the given file Paths. The filter method ensures that only paths containing the string 'data' are included. Then, the forEach method attempts to read each file using Files.readAllLines and prints their content. Since it is stated that the data.doc, data.txt, and data.xml files are accessible and contain text, there will be no exceptions, and the content of all three files will be printed.

Discussion
sansay61Option: D

D is correct.

fffffOption: D

D is correct, tested

aymanjOption: D

Answer is D .. Tested Stream<Path> paths = Stream.of (Paths. get("data.doc"), Paths. get("data.txt"), Paths. get("data.xml")); paths.filter(s-> s.toString().contains("data")).forEach( s -> { try { Files.readAllLines(s) .stream() .forEach(System.out::println); //line n1 } catch (IOException e) { System.out.println("Exception"); } } );

lchowenOption: B

Not sure if you guys really test the code...I created 3 files and successfully read the .txt file and .xml file. Only the .doc file fails. Answer is B for sure.

varconiteOption: B

Answer is B

mjcotan

Will be B if, for example, the first file don't exists, but the question says that there isn't any problem with the access to each file.

asdfjhfgjuaDCVOption: D

Answer is D.Tested

steefaandOption: D

D is correct.

iSnoverOption: D

The answer is the letter D, all files can be read and printed. Answer B could be correct but the question makes it clear that all files can be read and contain text.

Shad657Option: D

D is correct, tested. The given code reads from all 3 types of files- DOC, TXT, XML

tuyetanOption: B

B. Files.readAllLines() reads text files where each line is represented as a string. ".doc" files are binary files.

shivkumarx

a .doc file can still contain text

Kim514Option: D

D. The program prints the content of the three files.Tested.

WilsonKKerllOption: D

Answer is D.