Documente Academic
Documente Profesional
Documente Cultură
25-2
Four-score and 7.023
years ago.
76
= 91
94
39
****************************************************************************
Appending to a file:
Occasionally it may be desirable to append new content to the end of an existing file
rather that overwriting it as is the case with all of the previous code in this lesson. To
accomplish this, just make the following modification to the creation of the FileWriter
object:
FileWriter fw = new FileWriter(C:\\temp_Name\\Output1.out, true);
The new parameter, true, simply says, Yes, we want to append. If the file does not
already exist, the append mode will create and write to it.
Flushing the buffer:
The PrintWriter constructor will also accept a second parameter that indicates if we wish
to flush the buffer after each println. This forces storage to the disk at that moment
rather than waiting for the close method. This second parameter is not necessary if the
close method is issued at the end of output to the disk. The syntax for this is:
PrintWriter output = new PrintWriter(fw, true);
As an enrichment activity, take a look at Appendix F. There, you will learn the difference
between text and binary files.