Closing BufferedReader and System.in

后端 未结 2 1997
一个人的身影
一个人的身影 2020-11-27 08:17
Reader rdr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(rdr);
String s;
s = br.readLine();
br.close();
Scanner sc = new Scanner(System.         


        
相关标签:
2条回答
  • 2020-11-27 09:14

    Looks like you need:

    http://commons.apache.org/io/apidocs/org/apache/commons/io/input/CloseShieldInputStream.html

    Wrap that around System.in before making your reader, and then all will be well, since you won't do that when you are using a FileInputStream.

    0 讨论(0)
  • 2020-11-27 09:18

    If you just want to get input from keyboard by System.in, please use static BufferedReader wrapping InputStreamReader (also wrapping System.in). Like this:

     Public BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
    

    And is.close(); would be needed right before your application terminated.

    0 讨论(0)
提交回复
热议问题