Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

Exam 1z0-809 topic 1 question 12 discussion

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

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

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
pul26
Highly Voted 3 years, 3 months ago
public class FileLinesMain { public static void main(String[] args) throws IOException { Path file = Paths.get ("courses.txt"); Files.lines(file); Stream<String> fc = Files.lines (file); fc.forEach (s -> System.out.println(s)); } } Answer : D
upvoted 5 times
...
asdfjhfgjuaDCV
Most Recent 3 weeks, 4 days ago
Answer is D
upvoted 1 times
...
steefaand
1 month, 3 weeks ago
Selected Answer: D
D is correct.
upvoted 1 times
...
WilsonKKerll
2 years, 1 month ago
Answer is D. C must like is List<String> lines = Files.readAllLines(file);lines.stream().forEach(System.out::println);
upvoted 3 times
...
iamajavacompiler
2 years, 11 months ago
Both C and D work.
upvoted 2 times
Svetleto13
2 years, 9 months ago
Yes thats correct.We usually use readAllLines() for large files and lines() for small files.
upvoted 1 times
...
shivkumarx
2 weeks, 4 days ago
Except C does not reference the Files class, and its not implied in the question that it is statically imported
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 ...