• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

How To Get The Standard Input From Console In Java

January 25, 2014 //  by Krishna Srinivasan

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.

StdInputExample.java

package javabeat.net.core;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

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

}

Category: JavaTag: Java Basics, Java File IO

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « Marker Interfaces in Java
Next Post: Create Directory in Java »

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

What are Constructors in Java

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact