The InputStreamReader Class

The java.io.InputStreamReader class serves as a bridge between byte streams and character streams: It reads bytes from the input stream and translates them into characters according to a specified character encoding.

The encoding can be set in the constructor, or you can accept the platform's default encoding.

 public InputStreamReader(InputStream in)
 public InputStreamReader(InputStream in, String encoding) 
  throws UnsupportedEncodingException
For example, to attach an InputStreamReader to System.in with the default encoding, (generally ISO Latin-1):

InputStreamReader isr = new InputStreamReader(System.in);
On the other hand if you wanted to read a file that had been encoded using the Macintosh Symbol font, you might do this:

FileInputStream fis = new FileInputStream("symbol.txt");
InputStreamReader isr = new InputStreamReader(fis, "MacSymbol");
 public String getEncoding()
The getEncoding() method returns a string containing the name of the encoding used by this reader.

The other methods just override methods from java.io.Reader, but behave identically from the perspective of the programmer.

 public int read() throws IOException
 public int read(char c[], int off, int length) throws IOException
 public boolean ready() throws IOException
 public void close() throws IOException

Previous | Next | Top
Last Modified August 15, 1997
Copyright 1997 Elliotte Rusty Harold
elharo@metalab.unc.edu