Java InputStreamReader
Java InputStreamReader
is a class that reads bytes from an InputStream
and decodes them into characters using a specified character set. It is a bridge between byte streams and character streams.
Here are some of the methods available in the InputStreamReader
class:
read()
: This method reads a single character from the input stream and returns it as an integer. It returns -1 if the end of the stream has been reached.read(char[] cbuf)
: This method reads characters from the input stream and stores them in thecbuf
character array. It returns the number of characters read, or -1 if the end of the stream has been reached.read(char[] cbuf, int off, int len)
: This method reads up tolen
characters from the input stream, starting at the specifiedoff
offset, and stores them in thecbuf
character array. It returns the number of characters read, or -1 if the end of the stream has been reached.skip(long n)
: This method skipsn
characters in the input stream. It returns the actual number of characters skipped.ready()
: This method returns true if the input stream is ready to be read, or false otherwise.mark(int readAheadLimit)
: This method marks the current position in the input stream, so that it can be reset to that position later. ThereadAheadLimit
parameter specifies the maximum number of characters that can be read before the mark is invalidated.reset()
: This method resets the input stream to the position marked by the last call to themark()
method.getEncoding()
: This method returns the name of the character set being used by thisInputStreamReader
.close()
: This method closes the input stream and releases any system resources associated with it.