The java.io.Reader class

The methods of the java.io.Reader class are deliberately similar to the methods of the java.io.InputStream class. However rather than working with bytes, they work with chars.

The basic read() method reads a single character (which may may take between one and four bytes depending on the character set) and returns the character as an int between 0 and 65535. It returns -1 if the end of stream is seen.

 public int read() throws IOException
You can also read many characters into an array of chars. These methods return the number of bytes successfully read or -1 if the end of stream occurs.

 public int read(char[] text) throws IOException
 public abstract int read(char[] text, int offset, int length) 
  throws IOException
All the read() methods block until some input is available, an I/O error occurs, or the end of the stream is reached.

You can skip a certain number of characters. This method also blocks until some characters are available. It returns the number of characters skipped or -1 if the end of stream is reached.

 public long skip(long n) throws IOException
The ready() method returns true if the Reader is ready to be read from, false if it isn't. Generally this means the underying stream has available data.

 public boolean ready() throws IOException
Readers may or may not support marking and resetting, like input streams. The markSupported() method returns true if the underlying streams supports marking and resetting, false if it doesn't

 public boolean markSupported()
 public void mark(int readAheadLimit) throws IOException
 public void reset() throws IOException
Finally the close() method closes the Reader and releases any resources associated with it.

 public abstract void close() throws IOException

Previous | Next | Top
Last Modified July 6, 1999
Copyright 1997, 1999 Elliotte Rusty Harold
elharo@metalab.unc.edu