[ Back | Previous | Next ]

Using of a FileWriter, spefically to append to files

Package:
java.io.*
Product:
JDK
Release:
1.1.x
Related Links:
General
File
FilenameFilter
FileWriter
JPEGCodec
ObjectInputStream
OutputStream
PipedInputStream
PrintWriter
StreamTokenizer
Comment:
The use of a FileWriter is already demonstrated in a previous item about the PrintWriter.
See the example at the PrinterWriter and look carefully at the bold 
source code the boolean determins if a file is opened for "w" (write) or "a+" (append). So the newfile will 
be cleared every time the source is run, but appendfile will grow.
      bulkwriter = new PrintWriter( 
        new BufferedWriter( new FileWriter ("newfile", false)));
      bulksavwriter = new PrintWriter( 
        new BufferedWriter( new FileWriter ("appendfile", true)));
1