Java6 added a new utility class for reading input data from character
based devices including command line.
java.io.Console can be used to read input from command line, but unfortunately it doesn't work on most of IDE like Eclipse and
Netbeans. As per Javadoc call to
System.Console() will return attached console to JVM, if it has been started interactive command prompt or it will return null if JVM has been started using a background process or
scheduler job. Anyway
java.io.Console not only provides way to read input
from command prompt or Console but also reading passwords from console without echoing
it.
Console.readPassword() method reads password and returns a
character
array and password is masked during entering so that any peeping tom can
not see your password while you are entering it. here is a code example
of How to read password and input from command prompt or console using
java.io.Console. By the way apart from Console, you can also use Scanner or BufferedReader to read input from command prompt, as shown in this
example.