Java Methods of StringReader
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:
read()
: This method reads a single character from the stream and returns it as an integer value.read(char[] cbuf, int off, int len)
: This method reads characters from the stream into an array, starting at the specifiedoff
offset and reading up tolen
characters.skip(long n)
: This method skipsn
characters in the stream and returns the number of characters actually skipped.ready()
: This method returnstrue
if the stream is ready to be read, orfalse
otherwise.mark(int readAheadLimit)
: This method marks the current position in the stream, so that it can be returned to later using thereset()
method.reset()
: This method returns the stream to the position that was marked using themark()
method.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.