Java System.console.readPassword()要求用户在读取密码之前按enter键
通过console类读取输入时出现问题 readPassword()方法在控制台中按enter键之前不会开始读取,并将在控制台中继续显示字符 Post用户在控制台中输入enter键,读取密码开始从控制台读取字符 我想知道这是否与通过ReadPassword()函数中的synchronized关键字在控制台中获取锁有关 ReadPassword函数的代码-Java System.console.readPassword()要求用户在读取密码之前按enter键,java,console,Java,Console,通过console类读取输入时出现问题 readPassword()方法在控制台中按enter键之前不会开始读取,并将在控制台中继续显示字符 Post用户在控制台中输入enter键,读取密码开始从控制台读取字符 我想知道这是否与通过ReadPassword()函数中的synchronized关键字在控制台中获取锁有关 ReadPassword函数的代码- public char[] readPassword(String fmt, Object ... args) { char[
public char[] readPassword(String fmt, Object ... args) {
char[] passwd = null;
synchronized (writeLock) {
synchronized(readLock) {
try {
echoOff = echo(false);
} catch (IOException x) {
throw new IOError(x);
}
IOError ioe = null;
try {
if (fmt.length() != 0)
pw.format(fmt, args);
passwd = readline(true);
} catch (IOException x) {
ioe = new IOError(x);
} finally {
try {
echoOff = echo(true);
} catch (IOException x) {
if (ioe == null)
ioe = new IOError(x);
else
ioe.addSuppressed(x);
}
if (ioe != null)
throw ioe;
}
pw.println();
}
}
return passwd;
}