From 9d3d9c69a12987c01f67098894888a83e4f6073e Mon Sep 17 00:00:00 2001 From: "nshizirungudieumerci@gmail.com" Date: Wed, 12 Aug 2026 13:43:33 -0400 Subject: [PATCH] added a parsons problem to section 8.3 --- source/ch8_filehandling.ptx | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/source/ch8_filehandling.ptx b/source/ch8_filehandling.ptx index 7a7cf33..d9656b0 100644 --- a/source/ch8_filehandling.ptx +++ b/source/ch8_filehandling.ptx @@ -287,6 +287,44 @@ public class CreateFile {

You may have noticed that there are some new methods you haven't seen yet. The hasNextLine() method checks if there is a next line in the file, and returns false if there isn't. This method allows us to iterate over every line till there is no next line. The nextLine() method of the Scanner object returns the next line in the file as a string.

+ + + +

+ Construct the part of a Java program that opens a file with a Scanner and + prints each line until there are no more lines. Drag the blocks into the correct order on the right. +

+
+ + + + try (Scanner fileReader = new Scanner(new File(filename))) { + + + try (Scanner fileReader = new Scanner(filename)) { + + + + + + while (fileReader.hasNextLine()) { + + + while (fileReader.nextLine()) { + + + + + String data = fileReader.nextLine(); + System.out.println(data); + + + + } + } + + +