Which code fragment can be inserted at line n1 to enabl…

Given the code fragment:
Path file = Paths.get (“courses.txt”);
// line n1
Assume the courses.txt is accessible.
Which code fragment can be inserted at line n1 to enable the code to print the content of the courses.txt
file?

Given the code fragment:
Path file = Paths.get (“courses.txt”);
// line n1
Assume the courses.txt is accessible.
Which code fragment can be inserted at line n1 to enable the code to print the content of the courses.txt
file?

A.
List<String> fc = Files.list(file);
fc.stream().forEach (s – > System.out.println(s));

B.
Stream<String> fc = Files.readAllLines (file);
fc.forEach (s – > System.out.println(s));

C.
List<String> fc = readAllLines(file);
fc.stream().forEach (s – > System.out.println(s));

D.
Stream<String> fc = Files.lines (file);
fc.forEach (s – > System.out.println(s));



Leave a Reply 7

Your email address will not be published. Required fields are marked *


CompileTester

CompileTester

D

smh

smh

did not get it. Please advise.

Berti John

Berti John

D. is correct with this modification
Stream fc = Files.lines(file);
fc.forEach(System.out::println); –> modification

smh

smh

c and d both work but i will also prefer D as this is correct code.

Berti John

Berti John

D. is correct