From 3e64cedc0d08358d2273085676e8037d4290e861 Mon Sep 17 00:00:00 2001
From: Habiba Sorour
Date: Mon, 3 Aug 2026 23:46:36 +0300
Subject: [PATCH 1/3] added listing tags
---
source/ch8_filehandling.ptx | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/source/ch8_filehandling.ptx b/source/ch8_filehandling.ptx
index ba5d0cf..329a7f3 100644
--- a/source/ch8_filehandling.ptx
+++ b/source/ch8_filehandling.ptx
@@ -165,6 +165,8 @@ public class CreateFile {
Consider the following Python code example that reads each line of the file and prints it to the console.
+
+ Data file for reading example
1
@@ -177,8 +179,9 @@ public class CreateFile {
8
-
-
+
+
+
filename = "myfile.txt"
try:
@@ -192,12 +195,14 @@ public class CreateFile {
print("file could not be opened")
+
The following Java code functions very similarly to the previous Python. The main difference here is that unlike Python, in Java we use the Scanner object to iterate through and read lines in the file. You will notice that the structure of the Java code is still similar to the Python; Both use a try and catch statement to read the file and catch any errors.
-
+
+
import java.io.File;
import java.io.FileNotFoundException;
@@ -218,6 +223,7 @@ 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.
From 9564a2f690d1c8f1d4471607e160cc60b677a972 Mon Sep 17 00:00:00 2001
From: Habiba Sorour
Date: Mon, 3 Aug 2026 23:55:06 +0300
Subject: [PATCH 2/3] add listing to text
---
source/ch8_filehandling.ptx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/source/ch8_filehandling.ptx b/source/ch8_filehandling.ptx
index 329a7f3..c6597dd 100644
--- a/source/ch8_filehandling.ptx
+++ b/source/ch8_filehandling.ptx
@@ -163,7 +163,7 @@ public class CreateFile {
Let’s take a look at how we can use Python to understand how read file contents in Java. In order to read files generally you iterate through each line in the file and read the line's content. In Java, you read files in a very similar way, however in Java we will use the Scanner class in order to iterate through the lines.
- Consider the following Python code example that reads each line of the file and prints it to the console.
+ Consider that reads each line of and prints it to the console.
Data file for reading example
@@ -198,7 +198,7 @@ public class CreateFile {
- The following Java code functions very similarly to the previous Python. The main difference here is that unlike Python, in Java we use the Scanner object to iterate through and read lines in the file. You will notice that the structure of the Java code is still similar to the Python; Both use a try and catch statement to read the file and catch any errors.
+ functions very similarly to . The main difference here is that unlike Python, in Java we use the Scanner object to iterate through and read lines in the file. You will notice that the structure of the Java code is still similar to the Python; Both use a try and catch statement to read the file and catch any errors.
From 09c9d407bcb22bbb5572f03340f2347f5da1e5cb Mon Sep 17 00:00:00 2001
From: Habiba Sorour
Date: Tue, 4 Aug 2026 00:01:43 +0300
Subject: [PATCH 3/3] add listing to text
---
source/ch8_filehandling.ptx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source/ch8_filehandling.ptx b/source/ch8_filehandling.ptx
index c6597dd..b0e0a49 100644
--- a/source/ch8_filehandling.ptx
+++ b/source/ch8_filehandling.ptx
@@ -167,7 +167,7 @@ public class CreateFile {
Data file for reading example
-
+
1
2