title: Read key from java console exception
body: <p>I want to read a key from console but I get this exception and I am pretty stacked on it. I would appreciated any help!</p>
  
  <pre><code>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;
      }
  </code></pre>
  
  <blockquote>
    <p>java.io.IOException: Stream closed    at
    java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:162)
      at 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)</p>
  </blockquote>