小编Ziv*_*Ziv的帖子

当读取长度大于目标长度时,System.in.read方法不会抛出ArrayIndexOutOfBoundsException

我正在阅读Java™I/O,第2版这本书,这里有以下代码:

try {
  byte[] b = new byte[10];
  System.in.read(b);
}
catch (IOException ex) {
  System.err.println("Couldn't read from System.in!");
}
Run Code Online (Sandbox Code Playgroud)

从书中引用:

"..没有什么可以阻止你尝试将更多数据读入数组而不是适合.如果你这样做,read()抛出一个ArrayIndexOutOfBoundsException .."

但是,当我运行此代码并输入超过10个字符时,不会ArrayIndexOutOfBoundsException抛出; 为什么会这样?

java exception

0
推荐指数
1
解决办法
206
查看次数

标签 统计

exception ×1

java ×1