title: Java code style for open stream try/finally block
body: <p>This is a code style question.  I notice much example code including some <a href="http://download.oracle.com/javase/tutorial/essential/io/file.html#readStream" rel="noreferrer">examples from Oracle</a> ensure that a stream is closed in the following manner:</p>
  
  <pre><code>InputStream in = null;
  try {
      in = acquireStream();
      ...
  } finally {
      if (in != null) in.close();
  }
  </code></pre>
  
  <p>Note the initialization to null and check for null in the <code>finally</code> block.</p>
  
  <p>I tend to write code like this:</p>
  
  <pre><code>InputStream in = acquireStream();
  try {
      ...
  } finally {
      in.close();
  }
  </code></pre>
  
  <p>Are there advantages or disadvantages to either approach?  I like my style because I don't need the null check.  Also I like to avoid <code>null</code> when possible.  But since the Oracle style is so common in online examples, I'm wondering if mine has some hidden error.</p>
  
  <p>I ask the same question for <code>InputStream</code>, <code>OutputStream</code>, <code>java.sql.Connection</code>, <code>java.sql.PreparedStatement</code>, etc.  I tend to acquired the resource outside the <code>try</code> block and then close it in <code>finally</code> without a null check.  Is there anything I am missing other than stylistic differences?</p>
  
  <p>Thanks.</p>