I am trying to get the input from the from the user (hidden)
and trying to print that password, but the console is null and getting NullPointerException.
Is readPassword() supported in java? What is the substitute for this?
Console cons;
if((cons = System.console()) != null) {
char[] password = null;
try {
System.out.println("Enter the password :");
password=cons.readPassword();
System.out.println("Your password is" + new String(password));
} finally {
if(password != null) {
java.util.Arrays.fill(password,' ');
}
}
} else {
throw new RuntimeException("can't get password...No console");
}