diff --git a/source/ch8_filehandling.ptx b/source/ch8_filehandling.ptx index aa86bf3..eba0f10 100644 --- a/source/ch8_filehandling.ptx +++ b/source/ch8_filehandling.ptx @@ -240,10 +240,11 @@ public class CreateFile {
- Let us create the framework for a class that will write to a file. Let's call this class
- Next, we will create a
- The Java code to create a
- In this next step, we will use the
- And the Java equivalent. This is almost completely identical except for the second line, which is very important!
+
@@ -295,10 +303,11 @@ public class CreateFile {
- Next, we will again add the required try/catch blocks utilizing the
- And the equivalent Java code:
+
- And that's it! We will add our code to the foundational code for a complete program. First, an example of equivalent Python code:
+ And that's it! We will add our code to the foundational code for a complete program. First,
try:
with open("myfile.txt", "w") as my_writer:
@@ -345,16 +363,22 @@ public class CreateFile {
traceback.print_exc()
- The completed Java code:
+
import java.io.FileWriter;
import java.io.IOException;
@@ -372,8 +396,10 @@ public class CreateFile {
}
}
}
-
+ ~
@@ -382,22 +408,30 @@ public class CreateFile {
- Speaking of overwriting data, what if we want to append text to the end of any text already in
- Now, when we use
import java.io.FileWriter;
import java.io.IOException;
@@ -417,32 +451,40 @@ public class CreateFile {
}
- Then if we run the program twice, the contents of
+++ File successfully updated!File successfully updated! -
- This doesn't look very good! If we want each additional write to appear on a new line? A simple solution is to use the
- Running the code with the newline character twice will result in the following contents in myfile.txt:
+ Running the code with the newline character twice will result in the following contents in myfile.txt as
+++ File successfully updated! File successfully updated! -