Extends Writer.
Its purpose is to write output data in commonly readable form (text).
Converts primitive data into text format, then sends it to the writer.
Does not throw exceptions, success can be checked with checkError() method.
Uses optional auto flushing (specified with constructor) when using println() or printf() methods.
After closing the stream, any method will raise exception.
The PrintWriter implements the AutoClosable interface, the try-with-resources statement can be used to ensure proper closing.
Uses default character set but other encoding (e.g. UTF8 or UTF16) can be used as well.
The written data can be formatted. The methodology follows the String formatting.
Constructors:
use other writer (e.g. a previously declared FileWriter)
use other output stream (e.g. a previously declared FileOutputStream)
use an output file name
Constructor parameters:
(writer or output stream)
(writer or output stream, boolean autoFlush)
(writer or output stream, boolean autoFlush, Charset charset)
EXAMPLE FOR USAGE:
EXAMPLE FOR USAGE WITH TRY-WITH-RESOURCES: