How to find unclosed I/O resources in Java?
问题 Many I/O resources in Java such as InputStream and OutputStream need to be closed when they are finished with, as discussed here. How can I search my project for places where such resources are not being closed, e.g. this kind of error: private void readFile(File file) throws IOException { InputStream in = new FileInputStream(file); int nextByte = in.read(); while (nextByte != -1) { // Do something with the byte here // ... // Read the next byte nextByte = in.read(); } // Oops! Not closing