Java Methods of StringReader

www.igi‮‬ftidea.com

The StringReader class provides several methods that can be used to read character streams from a string. Here are some of the most commonly used methods:

  1. read(): This method reads a single character from the stream and returns it as an integer value.

  2. read(char[] cbuf, int off, int len): This method reads characters from the stream into an array, starting at the specified off offset and reading up to len characters.

  3. skip(long n): This method skips n characters in the stream and returns the number of characters actually skipped.

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

  5. mark(int readAheadLimit): This method marks the current position in the stream, so that it can be returned to later using the reset() method.

  6. reset(): This method returns the stream to the position that was marked using the mark() method.

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

Note that many of these methods can throw an IOException if there is an error while reading from the stream. Therefore, it is important to handle exceptions appropriately when using these methods.