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?
To print the content of the 'courses.txt' file, the appropriate method is to read all the lines of the file into a List using Files.readAllLines(file). This List can then be streamed and each line can be printed. The Files.readAllLines function returns a List of Strings, where each String is a line from the file, which can then be processed using stream(). The other options either incorrectly use Files.list, which is for listing files in a directory, or incorrectly handle Streams.
C,tested.
C is the correct
C is correct.
C is correct.
option D would be right if use method lines(path) rather than list(path)
Correct answer is C static List<String> readAllLines(Path path) - Read all lines from a file.
Option D, correct answer.
In what parallel universe is this the correct answer? static Stream<Path> list(Path dir) - Return a lazily populated Stream, the elements of which are the entries in the directory.