title: Proper way to close an OutputStream in Java?
body: <p>This almost seems silly but what is the most reliable pattern to follow when closing an OutputStream? Right now I have something like the following which just seem to be try-catch-finally-overkill:</p>
  
  <pre><code>private void writeContentsToFile(OutputStream ostream, Properties contents) {
      try {
          contents.store(ostream, "comments");
      }
      catch (IOException e) {
          throw new ResourceException("Failed to write contents", e);
      }
      finally {
          try {
              ostream.close();
          }
          catch (IOException e) { /* what can be done here anyway? */ }
      }
  }
  </code></pre>
  
  <p>Why close throws a checked exception is still a mystery to me. I can create wrapper method that does the close/catch block but if there is something already out there like <code>FileUtil.closeFileAndThrowUncheckedException()</code> I would like to use it. This gets a bit more useful when you have lots of smaller projects with lots of devs; one way to do it right.</p>