Extends Reader.
Extended by FileReader.
Converts data of bytes coming from a StreamReader (any subclasses) into data of characters. Therefore, it is a bridge between byte streams and character streams, reads bytes from an input stream as characters.
For 1-byte characters (ASCII) using an InputStream then convert the output to a String through the new String(byteArray) constructor is valid.
For minimum 2-byte characters (UTF-8, Unicode), the InputStreamReader is needed since it can read more bytes together as one character.
After building the bridge over it, the handled input 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 input stream source.
After closing the stream, any method will raise exception.
The InputStreamReader implements the AutoClosable interface, the try-with-resources statement can be used to ensure proper closing.
Constructor parameters:
- (FileInputStream fileInputStream): links the bridge to the input stream (e.g. FileInputStream), default character coding
- (FileInputStream fileInputStream, Charset charset): links the bridge to the input stream, charset character coding
The defined character coding will be forced during accessing the source stream.
Available methods are below.
EXAMPLE FOR USAGE:
EXAMPLE FOR USAGE WITH TRY-WITH-RESOURCES:
EXAMPLE FOR USING CHARACTER CODINGS: