I am using System.console()
in order to read user password.
My code:
Console console = System.console();
if (console == null) {
throw new RuntimeException("No console is available for input");
}
System.out.print("Enter the password: ");
String password = new String(console.readPassword());
It's working fine when I am running it straightforward (from Redhat
).
The problem is when I try to read the password from a text file:
java -jar my_jar.jar < password.txt
I get :
No console is available for input.
How can I solve it ?