Skip to content

Commit ec29666

Browse files
committed
Removed paragraph and code on using lineseparator method for new lines.
1 parent c55c7be commit ec29666

1 file changed

Lines changed: 3 additions & 16 deletions

File tree

source/ch8_filehandling.ptx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,6 @@
363363
</code>
364364
</program>
365365

366-
<p>
367-
Files in a specific directory can be written to using the same technique as the last section in which file paths are specified, with two back slashes used in Windows environments.
368-
</p>
369-
370366
<note>
371367
<p>
372368
If a file does not already exist (for example, <c>myfile.txt</c> does not exist), the <c>write()</c> method will create the file. Despite this, it is still a good idea to create separate methods or classes for creating and writing to files. Not only is it good practice to ensure methods only accomplish one thing, but the <c>createNewFile()</c> method avoids overwriting files that already exist. Imagine a file with the name <c>myfile.txt</c> already exists and contains important information. Attempting to create a file using the <c>write()</c> method will delete that data forever.
@@ -382,7 +378,7 @@
382378
</pre>
383379

384380
<p>
385-
Now, when we use <c>write()</c> method like before, the text will be appended if there is already text in the document. If we were to update our code to include the <c>boolean</c> argument:
381+
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:
386382
</p>
387383
<datafile label="my-file-8-4-6" filename="myfile.txt" xml:id= "my-file-8-4-6" editable="yes">
388384
<pre>
@@ -419,7 +415,7 @@
419415
</pre>
420416

421417
<p>
422-
This doesn't look very good! If we want each additional write to appear on a new line? The first solution may be to use the <c>\n</c> newline character:
418+
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:
423419
</p>
424420

425421
<pre>
@@ -428,16 +424,7 @@
428424
</pre>
429425

430426
<p>
431-
The System.lineseseparator() method is a better solution. This method returns the system's default line separator, which is platform-dependent. For example, on Windows, it returns <c>\n</c>, while on Linux and macOS, it returns <c>\n</c>. Using this method ensures that your code works correctly across different operating systems:
432-
</p>
433-
434-
<pre>
435-
myWriter.write("File successfully updated!" + System.lineseparator()); // Added newline character
436-
myWriter.close();
437-
</pre>
438-
439-
<p>
440-
Running it twice will result in the following contents in myfile.txt:
427+
Running the code with the newline character twice will result in the following contents in myfile.txt:
441428
</p>
442429

443430
<pre>

0 commit comments

Comments
 (0)