[ Back | Previous | Next ]

Using the PrinterWriter

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 PrinterWriter is easy instead of using the JDK1.0.2 method of DataOutputStream writeBytes() we can
send output by means of a print, println, command.

The PrintWriter can be in combination with BufferedWriter and FileWriter. For example:

    //
    // Open bulk files.
    PrintWriter bulkwriter = null;
    PrintWriter bulksavwriter = null;
    String bulkline = null;
    try {
      bulkwriter = new PrintWriter( 
        new BufferedWriter( new FileWriter ("newfile", false)));
      bulksavwriter = new PrintWriter( 
        new BufferedWriter( new FileWriter ("appendfile", true)));

      bulkline += "ENTERINGDATE:today\n<>\n"; 

      bulkwriter.println( bulkline );
      bulksavwriter.println( bulkline );

      bulkwriter.flush();
      bulksavwriter.flush();
      
      bulkwriter.close();
      bulksavwriter.close();
      
    } catch (Exception e) {
      fh_log.writeLog("Vullen van de bulkfile mislukt.");
    }


1