From bf5eed8ed164d1f0b0cc3d882d4944f30ceab0ae Mon Sep 17 00:00:00 2001 From: Habiba Sorour Date: Tue, 4 Aug 2026 16:14:43 +0300 Subject: [PATCH 1/3] add listing tags --- source/ch8_filehandling.ptx | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/source/ch8_filehandling.ptx b/source/ch8_filehandling.ptx index ba5d0cf..6a7002c 100644 --- a/source/ch8_filehandling.ptx +++ b/source/ch8_filehandling.ptx @@ -9,17 +9,22 @@

File handling is an integral part of programming. Most programming languages have the ability to create, read from, write to, and delete, files. In Python, most built-in libraries are available without needing to explicitly import additional packages, but some libraries like math do need to be imported. Consider the following.

- + + + import math print(math.sqrt(25)) +

Delete the first line that says import math and see what happens. The import math is needed. The same program in Java would look like this:

- + + + import java.lang.Math; @@ -30,6 +35,8 @@ } + +

Note the use of import java.lang.Math; in the above to import the Math class. Unlike Python, Java requires explicit import for most libraries, including the Math class and many classes related to file handling.

@@ -38,34 +45,42 @@ Much like the Math class, in order for your program to work with files you need use import. Java includes a class called File in the io library. This class allows you to create File objects, and use its public methods.

- + + import java.io.File; + +

The Scanner class from the util library will need to be imported if there is any need for a program to read a file. It should be noted that this library is unnecessary if the program will not be reading any data from a file.

- - + + import java.util.Scanner; +

The FileWriter class can be used to write to files. In the same way that the Scanner class isn't needed unless the program will read from a file, the FileWriter class isn't needed unless the program will write to a file.

- + + import java.io.FileWriter; +

Finally, these last two classes provide error handling and must be used in tandem with the File class when reading from or writing to files. IOException handles file creation and writing errors, while FileNotFoundException handles errors when trying to read files.

- + + import java.io.IOException; import java.io.FileNotFoundException; - + +
From 6d385b46cd3d9c79d5673827f87a549722a6fcb5 Mon Sep 17 00:00:00 2001 From: Habiba Sorour Date: Tue, 4 Aug 2026 16:16:24 +0300 Subject: [PATCH 2/3] fixed program tags --- source/ch8_filehandling.ptx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/ch8_filehandling.ptx b/source/ch8_filehandling.ptx index 6a7002c..4d98c52 100644 --- a/source/ch8_filehandling.ptx +++ b/source/ch8_filehandling.ptx @@ -36,7 +36,7 @@ - +

Note the use of import java.lang.Math; in the above to import the Math class. Unlike Python, Java requires explicit import for most libraries, including the Math class and many classes related to file handling.

@@ -46,7 +46,7 @@

- + import java.io.File; @@ -55,7 +55,7 @@ The Scanner class from the util library will need to be imported if there is any need for a program to read a file. It should be noted that this library is unnecessary if the program will not be reading any data from a file.

- + import java.util.Scanner; @@ -65,7 +65,7 @@

- + import java.io.FileWriter; @@ -75,7 +75,7 @@

- + import java.io.IOException; import java.io.FileNotFoundException; From b51dc8d2cc1ba16a12fa74ad86d61455fb5fd0b5 Mon Sep 17 00:00:00 2001 From: Habiba Sorour Date: Tue, 4 Aug 2026 16:24:47 +0300 Subject: [PATCH 3/3] added listing to txt --- source/ch8_filehandling.ptx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/ch8_filehandling.ptx b/source/ch8_filehandling.ptx index 4d98c52..3d6cb05 100644 --- a/source/ch8_filehandling.ptx +++ b/source/ch8_filehandling.ptx @@ -7,7 +7,7 @@
Class Imports

- File handling is an integral part of programming. Most programming languages have the ability to create, read from, write to, and delete, files. In Python, most built-in libraries are available without needing to explicitly import additional packages, but some libraries like math do need to be imported. Consider the following. + File handling is an integral part of programming. Most programming languages have the ability to create, read from, write to, and delete, files. In Python, most built-in libraries are available without needing to explicitly import additional packages, but some libraries like math do need to be imported. shows an example of importing the math library in Python.

@@ -20,10 +20,10 @@

- Delete the first line that says import math and see what happens. The import math is needed. The same program in Java would look like this: + Delete the first line that says import math and see what happens. The import math is needed. The same program in Java would look like .

- + import java.lang.Math; @@ -42,7 +42,7 @@

- Much like the Math class, in order for your program to work with files you need use import. Java includes a class called File in the io library. This class allows you to create File objects, and use its public methods. + Much like the Math class, in order for your program to work with files you need use import. Java includes a class called File in the io library shown in . This class allows you to create File objects, and use its public methods.

@@ -52,7 +52,7 @@

- The Scanner class from the util library will need to be imported if there is any need for a program to read a file. It should be noted that this library is unnecessary if the program will not be reading any data from a file. + The Scanner class from the util library will need to be imported if there is any need for a program to read a file as shown in . It should be noted that this library is unnecessary if the program will not be reading any data from a file.

@@ -61,7 +61,7 @@

- The FileWriter class can be used to write to files. In the same way that the Scanner class isn't needed unless the program will read from a file, the FileWriter class isn't needed unless the program will write to a file. + The FileWriter class can be used to write to files as shown in . In the same way that the Scanner class isn't needed unless the program will read from a file, the FileWriter class isn't needed unless the program will write to a file.

@@ -71,7 +71,7 @@

- Finally, these last two classes provide error handling and must be used in tandem with the File class when reading from or writing to files. IOException handles file creation and writing errors, while FileNotFoundException handles errors when trying to read files. + Finally, these last two classes provide error handling and must be used in tandem with the File class when reading from or writing to files as shown in . IOException handles file creation and writing errors, while FileNotFoundException handles errors when trying to read files.