public Object next() { try { String result = internal.readLine(); if (result == null) { throw new NoSuchElementException(); } else { return result; } } catch (IOException e) {
// The original exception is included in the message to notify the // client that an IOException has occurred. throw new NoSuchElementException(e.toString()); } }
请注重:要使其余的代码能使用修改过的方法,我们还必须:
导入 java.util.NoSuchElementException。 修正 hasNext,使其不再调用 next 来进行测试。最简单的修正方法是只要直接调用 internal.readLine()。