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:

  1. 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.

  2. read(char[] cbuf): This method reads characters from the input stream and stores them in the cbuf character array. It returns the number of characters read, or -1 if the end of the stream has been reached.

  3. read(char[] cbuf, int off, int len): This method reads up to len characters from the input stream, starting at the specified off offset, and stores them in the cbuf character array. It returns the number of characters read, or -1 if the end of the stream has been reached.

  4. skip(long n): This method skips n characters in the input stream. It returns the actual number of characters skipped.

  5. ready(): This method returns true if the input stream is ready to be read, or false otherwise.

  6. mark(int readAheadLimit): This method marks the current position in the input stream, so that it can be reset to that position later. The readAheadLimit parameter specifies the maximum number of characters that can be read before the mark is invalidated.

  7. reset(): This method resets the input stream to the position marked by the last call to the mark() method.

  8. close(): This method closes the input stream and releases any system resources associated with it.