Skip to content

Commit c0fb145

Browse files
committed
added listing to text
1 parent 54e5c71 commit c0fb145

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

source/ch8_filehandling.ptx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public class CreateFile {
240240
</p>
241241

242242
<p>
243-
Let us create the framework for a class that will write to a file. Let's call this class <c>WriteFile</c>:
243+
<xref ref="write-file-class-java" text="type-global"/> shows the framework for a class that will write to a file. Let's call this class <c>WriteFile</c>.
244244
</p>
245245

246246
<listing xml:id="write-file-class-java">
@@ -258,7 +258,7 @@ public class CreateFile {
258258
</listing>
259259

260260
<p>
261-
Next, we will create a <c>FileWriter</c> object. Let's call it <c>myWriter</c>. The equivalent Python code to this operation is:
261+
Next, we will create a <c>FileWriter</c> object. Let's call it <c>myWriter</c>. <xref ref="filerwriter-object-python" text="type-global"/> shows the code to create a <c>myWriter</c> object in Python.
262262
</p>
263263
<listing xml:id="filerwriter-object-python">
264264
<program language="python">
@@ -267,7 +267,7 @@ public class CreateFile {
267267
</listing>
268268

269269
<p>
270-
The Java code to create a <c>FileWriter</c> object is:
270+
<xref ref="filerwriter-object-java" text="type-global"/> shows the Java code to create a <c>FileWriter</c> object. Note that the <c>FileWriter</c> object is created with the name of the file to write to as an argument. If the file does not exist, it will be created. If it does exist, it will be overwritten.:
271271
</p>
272272

273273
<listing xml:id="filerwriter-object-java">
@@ -277,7 +277,7 @@ public class CreateFile {
277277
</listing>
278278

279279
<p>
280-
In this next step, we will use the <c>write()</c> method from the FileWriter class. This method will take any data within the parenthesis and write that data to the file selected. The <c>write()</c> method takes most standard data types. First, how this step is completed with Python:
280+
In this next step, we will use the <c>write()</c> method from the FileWriter class. This method will take any data within the parenthesis and write that data to the file selected. The <c>write()</c> method takes most standard data types. The <xref ref="write-and-close-python" text="type-global"/> shows the code to write to a file in Python.
281281
</p>
282282
<listing xml:id="write-and-close-python">
283283
<program language="python">
@@ -286,7 +286,7 @@ public class CreateFile {
286286
</listing>
287287

288288
<p>
289-
And the Java equivalent. This is almost completely identical except for the second line, which is very important!
289+
<xref ref="write-and-close-java" text="type-global"/> shows the Java equivalent. This is almost completely identical except for the second line, which is very important!
290290
</p>
291291

292292
<listing xml:id="write-and-close-java">
@@ -303,7 +303,7 @@ public class CreateFile {
303303
</note>
304304

305305
<p>
306-
Next, we will again add the required try/catch blocks utilizing the <c>IOException</c> class. Just like with creating files, the program will not compile without these crucial additions! We will also add some print statements to inform us of the success of the file write operation. First, a Python example:
306+
Next, we will again add the required try/catch blocks utilizing the <c>IOException</c> class. Just like with creating files, the program will not compile without these crucial additions! We will also add some print statements to inform us of the success of the file write operation. <xref ref="file-try-catch-python" text="type-global"/> shows the code to write to a file in Python.
307307
</p>
308308

309309
<listing xml:id="file-try-catch-python">
@@ -320,7 +320,7 @@ public class CreateFile {
320320
</listing>
321321

322322
<p>
323-
And the equivalent Java code:
323+
<xref ref="file-try-catch-java" text="type-global"/> shows the Java equivalent.
324324
</p>
325325

326326
<listing xml:id="file-try-catch-java">
@@ -338,7 +338,7 @@ public class CreateFile {
338338
</listing>
339339

340340
<p>
341-
And that's it! We will add our code to the foundational code for a complete program. First, an example of equivalent Python code:
341+
And that's it! We will add our code to the foundational code for a complete program. First, <xref ref="file-write-full-python" text="type-global"/> shows the completed Python code.
342342
</p>
343343
<data xml:id="my-file-8-4-2">
344344
<title>Data file for writing example</title>
@@ -365,7 +365,7 @@ public class CreateFile {
365365
</listing>
366366

367367
<p>
368-
The completed Java code:
368+
<xref ref="file-write-full-java" text="type-global"/> shows the completed Java code.
369369
</p>
370370
<data xml:id="my-file-8-4-5">
371371
<title>Data file for writing example</title>
@@ -403,7 +403,7 @@ public class CreateFile {
403403
</note>
404404

405405
<p>
406-
Speaking of overwriting data, what if we want to append text to the end of any text already in <c>myfile.txt</c>? To accomplish this, we can pass a <c>boolean</c> argument along with the file name when creating a new data argument:
406+
Speaking of overwriting data, what if we want to append text to the end of any text already in <c>myfile.txt</c>? To accomplish this, we can pass a <c>boolean</c> argument along with the file name when creating a new data argument as shown in <xref ref="append-true" text="type-global"/>.
407407
</p>
408408

409409
<listing xml:id="append-true">
@@ -413,8 +413,8 @@ public class CreateFile {
413413
</listing>
414414

415415
<p>
416-
Now, when we use <c>write()</c> method like before, the text will be appended if there is already tSext in the document. If we were to update our code to include the <c>boolean</c> argument:
417-
</p>
416+
Now, when we use <c>write()</c> method like before, the text will be appended if there is already tSext in the document. If we were to update our code to include the <c>boolean</c> argument as shown in <xref ref="file-write-with-append" text="type-global"/>.
417+
418418
<data xml:id="my-file-8-4-6">
419419
<title>Data file for writing example</title>
420420
<datafile label="my-file-8-4-6" filename="myfile" editable="yes">
@@ -448,7 +448,7 @@ public class CreateFile {
448448
</listing>
449449

450450
<p>
451-
Then if we run the program twice, the contents of <c>myfile.txt</c> would be:
451+
Then if we run the program twice, the contents of <c>myfile.txt</c> would be as <xref ref="file-write-with-append-output" text="type-global"/> shows.
452452
</p>
453453

454454
<listing xml:id="file-write-with-append-output">
@@ -458,7 +458,7 @@ public class CreateFile {
458458
</listing>
459459

460460
<p>
461-
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 <c>\n</c> newline character:
461+
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 <c>\n</c> newline character as <xref ref="file-write-with-newline" text="type-global"/> shows.
462462
</p>
463463

464464
<listing xml:id="file-write-with-newline">
@@ -469,7 +469,7 @@ public class CreateFile {
469469
</listing>
470470

471471
<p>
472-
Running the code with the newline character twice will result in the following contents in myfile.txt:
472+
Running the code with the newline character twice will result in the following contents in myfile.txt as <xref ref="file-write-with-newline-output" text="type-global"/> shows.
473473
</p>
474474

475475
<listing xml:id="file-write-with-newline-output">

0 commit comments

Comments
 (0)