PrintWriter(OutputStream out, boolean autoFlush)
flush()
is probably not required in your example.
What it does is ensure that anything written to the writer prior to the call to flush()
is written to the underlying stream, rather than sit in some internal buffer.
The method comes in handy in several types of circumstances:
-
If another process (or thread) needs to examine the file while it's being written to, and it's important that the other process sees all the recent writes.
-
If the writing process might crash, and it's important that no writes to the file get lost.
-
If you're writing to the console, and need to make sure that every message is shown as soon as it's written.
PrintStream
. It does not contain methods for writing raw bytes, for which a program should use unencoded byte streams.
Unlike the PrintStream
class, if automatic flushing is enabled it will be done only when one of the println, printf, or format methods is invoked, rather than whenever a newline character happens to be output. These methods use the platform's own notion of line separator rather than the newline character.
Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError()
.
PrintWriter
swallows exceptions. See the Javadoc. You need to call checkError()
. Better still, use BufferedWriter
, which doesn't swallow them. You're probably running up against an apple sandbox permission problem unless your applet is signed.