The InputStreamReader Class

The 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 with the default encoding:

InputStreamReader isr = new InputStreamReader(;

On the other hand if you wanted to read a file that had been encoded using UTF-8, you might do this:

FileInputStream fis = new FileInputStream("file.utf8.txt");
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");

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, but behave identically from the perspective of the programmer.

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

Previous | Next | Top | Cafe au Lait

Copyright 1997 Elliotte Rusty Harold
Last Modified August 15, 1997