Extends Writer.
Extended by FileWriter.
Converts data of characters to data of bytes for a StreamWriter (any subclasses). Therefore, it is a bridge between character streams and byte streams, writes characters to an output stream as bytes.
For 1-byte characters (ASCII) using simplier converter methods to bytes then using an OutputStream is valid.
For minimum 2-byte characters (UTF-8, Unicode), the OutputStreamWriter is needed since it can write more bytes together per one character.
After building the bridge over it, the handled output stream needs no further access, methods of the bridge can be used.
In case a method tries to access data after the end of the source (accessed length is greater than the actually available), exception raises.
The stream must be closed after processing in order to release the output stream.
After closing the stream, any method will raise exception.
The OutputStreamWriter implements the AutoClosable interface, the try-with-resources statement can be used to ensure proper closing.
Constructor parameters:
(FileOutputStream fileOutputStream): links the bridge to the output stream (e.g. FileOutputStream), default character coding
(FileOutputStream fileOutputStream, Charset charset): links the bridge to the output stream, charset character coding
The defined character coding will be forced during accessing the destination stream.
Available methods are below.
EXAMPLE FOR USAGE:
EXAMPLE FOR USAGE WITH TRY-WITH-RESOURCES:
EXAMPLE FOR USING CHARACTER CODINGS: