从java控制台异常中读取密钥

时间:2013-08-21 08:20:44

标签: java bufferedreader inputstreamreader

我想从控制台读取一个键,但是我得到了这个例外,而且我非常喜欢它。我很感激任何帮助!

public char readKey() {
        char key = ' ';
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            key = (char) br.read();
        } catch (IOException e) { 
            e.printStackTrace();
        }
        return key;
    }
  

java.io.IOException:Stream关闭了   java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:162)     在java.io.BufferedInputStream.read(BufferedInputStream.java:325)at   sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)at   sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)at   sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)at   java.io.InputStreamReader.read(InputStreamReader.java:184)at   java.io.BufferedReader.fill(BufferedReader.java:154)at   java.io.BufferedReader.read(BufferedReader.java:175)

0 个答案:

没有答案