exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 5 discussion

Actual exam question from Oracle's 1z0-809
Question #: 7
Topic #: 2
[All 1z0-809 Questions]

Given the code fragment:
Path file = Paths.get ("courses.txt");
// line n1
courses.txt is accessible.

Assume the -
line n1 to enable the code to print the content of the courses.txt file?
Which code fragment can be inserted at

  • 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);
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Innovation
Highly Voted 4 years, 6 months ago
Files.readAllLines returns a list of strings. the correct answer is C
upvoted 8 times
...
steefaand
Most Recent 5 months, 3 weeks ago
Selected Answer: C
C is correct since readAllLines returns List rather than Stream. For this to be true assume that Files is static imported and there is no need for it to be present in front of readAllLines.
upvoted 1 times
...
iSnover
5 months, 4 weeks ago
Selected Answer: C
Files.readAllLines returns a list of strings. The correct answer is C
upvoted 1 times
...
WilsonKKerll
2 years, 4 months ago
Answer is B. Option D is incorrect because it can't print courses.txt, must add fc.forEach(System.out::print).
upvoted 1 times
WilsonKKerll
2 years, 4 months ago
I mean answer is C.
upvoted 1 times
...
...
M_Jawad
4 years, 6 months ago
B is incorrect because Files.readAllLines(file) return a list of strings not a Stream
upvoted 2 times
...
M_Jawad
4 years, 6 months ago
D is correct with this addition : fc.forEach(n -> System.out.println(n));
upvoted 3 times
...
Destroyer
4 years, 7 months ago
The correct answer is D
upvoted 1 times
...
Ritesh_
4 years, 9 months ago
C can be the answer with below modification. Stream<String> fc = Files.readAllLines (file).stream();
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago