通过new InputStreamReader(System.in)输入的字符想写入某个文本,但是不知道怎么停下来
不见得叫我一直输啊输,,,,,

解决方案 »

  1.   

    判断System.in,是否到结尾啦嘛
      

  2.   

    System.in  好像是永远不会有结尾的
      

  3.   

    书上说ctrl+z就会停止,结果不行
      

  4.   

    可以判断一下
    public void talk () throws IOException {
           BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
           String msg = null;
           while ((msg = br.readLine())!= null) {
               if (msg.equals("bye")) {
                   break;
               }
           }
        }
      

  5.   

    结尾是要有一个信号的。
    一般是这样(引用上面的代码):
    while ((msg = br.readLine())!= null) { 
    直接敲回车的时候就不满足上面的条件了。也就是说,在一个新行直接回车就结束了。