Console Class

Console class can be used to access character based devices.

Program :


 import java.io.*; 
class inp
{
public static void main(String arg[]) throws IOException
{
Console co=System.console();
String st=co.readLine();
System.out.println(st);

}
}

Reading Password securely in java

readPassword() method can be used to take password from user. Password must be unseen from user.

Program :


 import java.io.*; 
class inp
{
public static void main(String arg[]) throws IOException
{
Console co=System.console();
char[] pwd=co.readPassword("Password:");
System.out.println("password given by user:"+pwd);
}
}