Assume customers.txt is accessible and contains multiple lines.
Which code fragment prints the contents of the customers.txt file?
Assume customers.txt is accessible and contains multiple lines.
Which code fragment prints the contents of the customers.txt file?
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.
the correct answer is D
D is the answer
D is correct.
Files.lines(path) return a Stream so D is correct
The correct answer is D!!.