关于system.in输入流 问题!

如图所示!如果是读取文件,当读到文件末尾条件等于null,退出循环。。而这里如果不输入内容,那程序是在哪里阻塞着???为什么??它不是应该一直readline吗??图片图片

是这一句阻塞了。

str=br.readLine(); 

你输入完毕后,会进入第二次等待输入状态。
在BufferedReader中有个方法叫fill方法,会一直监听控制台输入,可以具体的看一下。

你发的图看不清楚啊,分辨率太小了。

在java.io.BufferedReader中有这个方法。下面是这个方法的介绍,你可以看看。是不是你的JDK没有源码啊?


    /**
     * Fills the input buffer, taking the mark into account if it is valid.
     */
    private void fill() throws IOException {
    int dst;
    if (markedChar <= UNMARKED) {
        /* No mark */
        dst = 0;
    } else {
        /* Marked */
        int delta = nextChar - markedChar;
        if (delta >= readAheadLimit) {
        /* Gone past read-ahead limit: Invalidate mark */
        markedChar = INVALIDATED;
        readAheadLimit = 0;
        dst = 0;
        } else {
        if (readAheadLimit <= cb.length) {
            /* Shuffle in the current buffer */
            System.arraycopy(cb, markedChar, cb, 0, delta);
            markedChar = 0;
            dst = delta;
        } else {
            /* Reallocate buffer to accommodate read-ahead limit */
            char ncb[] = new char[readAheadLimit];
            System.arraycopy(cb, markedChar, ncb, 0, delta);
            cb = ncb;
            markedChar = 0;
            dst = delta;
        }
                nextChar = nChars = delta;
        }
    }

    int n;
    do {
        n = in.read(cb, dst, cb.length - dst);
    } while (n == 0);
    if (n > 0) {
        nChars = dst + n;
        nextChar = dst;
    }
    }

While(!EOF){
readline(...);
}
伪代码,仅供参考