How to use Console class in java?

This class is introduce in java 1.6 version. This class is used to read the contents from the keyboard. Console is a available in “io” package.

We can not object of console class directly. It can be created by using console method available in System class.


class Read1{

public static void main(String[] args) throws IOException{

Console c = System.console();

String name = c.readLine(“Enter your name:”);


Char[] pwd = c.readPassword(“Enter your password”);