How To Get The Standard Input From Console In Java

This simple example shows how to get the standard input from console in Java. When you run this program, it asks the user for the input, if you enter a value, it is printed in the console. Let’s try this example.



public class StdInputExample {
	public static void main(String args[]) {
		try {
			//BufferedReader with InputStreamReader
			BufferedReader bufferReader = new BufferedReader(new InputStreamReader(;
			String inputValue;

			//Reads and prints it
			while ((inputValue = bufferReader.readLine()) != null) {
				System.out.println("You entered : "+inputValue);
		} catch (IOException io) {


Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!