Learning Center
Plans & pricing Sign in
Sign Out



  • pg 1
									How to pass input from a console to a Java program ?.

In this section of blog, we will look into a tutorial and a simple Java
program, explaining how to pass input from a console to a Java program.
Usually, Input is given to the program from the standard input device
called as keyboard. In Java reading an input is not as simple as output.
Java API is full of several classes which can be used for the purpose of
reading the input from a keyboard. is a predefined stream object which can be used to read input.
But is a byte oriented stream, it can be used only to read
bytes. In order to make it read characters we usually wrap it across a
character oriented stream called as InputStreamReader. InputStreamReader
is a reader class which is been used to read characters. For reading the
input as string we wrap this byte stream to BufferedReader which buffers
In order to apply above concepts to these streams we follow these steps :

1. BufferedReader br = new BufferedReader(new

2. InputStreamReader isr = new InputStreamReader(;
   BufferedReader br = new BufferedReader(isr);

In order to read a string, we use method readLine on the BufferedReader
object as

  String read = br.readLine();

To top