尝试
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("");
}
当心,虽然,这doesn’t work与Eclipse控制台。你必须从真正的控制台/ shell /终端/提示运行程序才能测试它。