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));
D
did not get it. Please advise.
D. is correct with this modification
Stream fc = Files.lines(file);
fc.forEach(System.out::println); –> modification
c and d both work but i will also prefer D as this is correct code.
D. is correct
D
D