Reading Console Input in Java

You are currently viewing Reading Console Input in Java

Reading console input in simple java console applications is a very straight forward process. Java provides developers two predefined streams in the java.lang.System class to read and write data to and from standard input and output devices. System.out is a standard output stream which is Console by default and is predefined input stream which is Keyboard by default. To read user input in a console window we connect with other stream classes available in package.

Following code example shows you how to read user input in console window in java.


public class ConsoleInput
      public static void main(String[] args) throws Exception
            System.out.println("Enter Your Text: " );   
            InputStreamReader r = new InputStreamReader(;
            BufferedReader br = new BufferedReader(r); 
            String s = br.readLine(); 
READ ALSO:  Reading Text based Files in Java

Leave a Reply