Courseiva
Java Platform Overview and PackagingmediumDrag & DropObjective-mapped

1Z0-829 Java Platform Overview and Packaging Practice Question

Arrange the steps to read a file using NIO.2 Files.lines() in Java.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

1. Create a Path object using Paths.get("file.txt"). 2. Call Files.lines(path) to obtain a Stream<String>. 3. Process the stream using stream operations like forEach, filter, etc. 4. Close the stream by calling close() or using try-with-resources.

Files.lines() returns a Stream that must be closed to release file handles. The stream is lazily populated.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • 1. Create a Path object using Paths.get("file.txt"). 2. Call Files.lines(path) to obtain a Stream<String>. 3. Process the stream using stream operations like forEach, filter, etc. 4. Close the stream by calling close() or using try-with-resources.

    Why this is correct

    This is the correct order because Files.lines() requires a Path, returns a lazily populated Stream, and the stream must be closed to release file handles, typically after processing.

  • 1. Call Files.lines("file.txt") directly with a string. 2. Create a Path object. 3. Process the stream. 4. Close the stream.

    Why it's wrong here

    This is incorrect because Files.lines() expects a Path, not a string literal. Also, the stream is opened before the Path is created, which is logically backward.

  • 1. Create a Path object. 2. Process the stream (e.g., apply operations). 3. Call Files.lines(path) to get the stream. 4. Close the stream.

    Why it's wrong here

    This is incorrect because processing the stream before obtaining it is impossible; the stream must be obtained first to perform any operations.

  • 1. Create a Path object. 2. Call Files.lines(path) to get the stream. 3. Close the stream. 4. Process the stream.

    Why it's wrong here

    This is incorrect because closing the stream before processing it makes the stream unavailable for reading, resulting in a 'stream closed' exception.

About these practice questions

This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.