Попробуйте java.io.Console.readPassword
. Вы должны будете работать хотя бы на Java 6.
/**
* Reads a password or passphrase from the console with echoing disabled
*
* @throws IOError
* If an I/O error occurs.
*
* @return A character array containing the password or passphrase read
* from the console, not including any line-termination characters,
* or null if an end of stream has been reached.
*/
public char[] readPassword() {
return readPassword("");
}
Остерегайтесь, однако, этот не работает с консолью Eclipse. Вам нужно будет запустить программу из true console / shell / terminal / prompt, чтобы проверить ее.