Java Methods of Reader
Java Reader
is an abstract class for reading character streams, and it provides several methods to read character data from different sources.
Here are some of the methods available in the Reader
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.close()
: This method closes the input stream and releases any system resources associated with it.