← prev
Tóm Tắt
Java InputStreamReader
An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform’s default charset may be accepted.
Constructor
Constructor name
Description
InputStreamReader(InputStream in)
It creates an InputStreamReader that uses the default charset.
InputStreamReader(InputStream in, Charset cs)
It creates an InputStreamReader that uses the given charset.
InputStreamReader(InputStream in, CharsetDecoder dec)
It creates an InputStreamReader that uses the given charset decoder.
InputStreamReader(InputStream in, String charsetName)
It creates an InputStreamReader that uses the named charset.
Method
Modifier and Type
Method
Description
void
close()
It closes the stream and releases any system resources associated with it.
String
getEncoding()
It returns the name of the character encoding being used by this stream.
int
read()
It reads a single character.
int
read(char[] cbuf, int offset, int length)
It reads characters into a portion of an array.
boolean
ready()
It tells whether this stream is ready to be read.
Example
Output:
I love my country The file.txt contains text "I love my country" the InputStreamReader reads Character by character from the file
Next Topic
Java PushbackInputStream Class
← prev
next →