Read standard input (stdin) with java.io.Console in Java

In JDK 1.6, reading standard input (stdin) changed to a simple approach using java.io.Console.

readLine takes input from FileDescriptor.in which is a handle to System.in which uses the InputStream class.

System.out.println("Enter text:");
// Note: console.readLine returns null when used from an IDE
String input = System.console().readLine();
System.out.println(input);

Using Scanner is a friendly approach when using an IDE.

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>