iterator() methods for File, Reader, InputStream, and DataInputStream return iterators that do not close their underlying streams. They should do this, to be consistent with iterative closure methods like eachLine() etc. A solution must take in account that a loop can be broken by an exception inside the loop, that is not caused by a resource read operation. Also in this case the resource must be closed.
See discussion at http://www.nabble.com/File-Iterator-leaves-Reader-open-tf3782079.html
.
To clarify problem a JUnit test case will is attached.
This results in the following consequences for application programmers:
All test methods that relate to handling of exceptions inside the loop can be removed from the attached JUnit file.