InputStreamReader in Java

InputStreamReader is used to read keys from the keyboard, initially we construct an InputStreamReader stream from System.in and then use the InputStreamReader class’s read method to read what the user has typed. InputStreamReader class is derived from the Reader class.

The following example just read keys from the keyboard and displays them.

Example:

/**
From InputStreamReaders.java
*/

import java.io.InputStreamReader;

/**
 *
 * @author JavaHotSpot
 */
public class InputStreamReaders
{
  public static void main(String args[])
  {
      try
      {
          int ch;
         
          InputStreamReader ins=new InputStreamReader(System.in);
         
          while((ch=ins.read())!=-1)
          {
              System.out.print((char)ch);
          }
      }
      catch(Exception ex)
      {
          System.err.println(ex);
      }
  }
}


Output:
Hello from java