title: How to find unclosed I/O resources in Java?
body: <p>Many I/O resources in Java such as InputStream and OutputStream need to be closed when they are finished with, as discussed <a href="http://www.coderanch.com/t/202922/Performance/java/Unclosed-File-input-stream">here</a>.</p>
  
  <p>How can I search my project for places where such resources are not being closed, e.g. this kind of error:</p>
  
  <pre><code>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 the InputStream
  }
  </code></pre>
  
  <p>I've tried some static analysis tools such as PMD and FindBugs, but they don't flag the above code as being wrong.</p>