[ Back | Previous | Next ]

How to read from an System.in Stream?

Package:
java.lang.*
Product:
JDK
Release:
1.0.2
Related Links:
General
General
General
General
General
General
General
General
General
Runtime
System
Comment:
The following code shows how to read from a System.in InputStream. By default the System.in stream echoes thru the OS its running under.
      int ch;
      while (true) {
        System.out.print(">");
        StringBuffer sb = new StringBuffer();
        while ( (ch = System.in.read()) != 13) {
          sb.append( (char) ch );
        }
        performCommand( sb.toString() );
        sb = null;
      }
1