Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java System.console.readPassword()要求用户在读取密码之前按enter键_Java_Console - Fatal编程技术网

Java System.console.readPassword()要求用户在读取密码之前按enter键

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[

通过console类读取输入时出现问题

readPassword()方法在控制台中按enter键之前不会开始读取,并将在控制台中继续显示字符

Post用户在控制台中输入enter键,读取密码开始从控制台读取字符

我想知道这是否与通过ReadPassword()函数中的synchronized关键字在控制台中获取锁有关

ReadPassword函数的代码-

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;
    }