论坛改名申请通道 作者: HM黄祥为 时间: 2013-3-10 19:21
那是因为你第一次调用br.close();的时候 级联关闭了system.in 而syste.in这个流关闭后即释放所有资源 无法再使用了 同时也无法使用java对其进行重新打开。
public final static InputStream in = nullInputStream();
这是in的定义.
然后去看nullInputStream();
/**
* The following two methods exist because in, out, and err must be
* initialized to null. The compiler, however, cannot be permitted to
* inline access to them, since they are later set to more sensible values
* by initializeSystemClass().
*/
private static InputStream nullInputStream() throws NullPointerException {
if (currentTimeMillis() > 0)
return null;
throw new NullPointerException();
}
从注释也能看出来in 初始化为null了.
然后实际运行时是通过initializeSystemClass()来初始化的.
再看
private static void initializeSystemClass() {
的代码,里面有
setIn0(new BufferedInputStream(fdIn));
这个setIn0就是让
in = new BufferedInputStream(fdIn);
不过这是有c语言来实现的,因为in是final的,你不能通过java来改变它.