title: What are the benefits to using a try-finally block for working with an input stream?
body: <p>Here is a Java example I found online:</p>
  
  <pre><code>try{
        //use buffering
        InputStream file = new FileInputStream("quarks.ser");
        InputStream buffer = new BufferedInputStream(file);
        ObjectInput input = new ObjectInputStream (buffer);
        try{
          //deserialize the List
          List&lt;String&gt; recoveredQuarks = (List&lt;String&gt;)input.readObject();
          //display its data
          for(String quark: recoveredQuarks){
            System.out.println("Recovered Quark: " + quark);
          }
        }
        finally{
          input.close();
        }
  } catch(ClassNotFoundException ex){
        //some exception handling
  }
  </code></pre>
  
  <p>In the above, what are the benefits of using a try-finally block to execute some processing with the input before closing the input? In other words, what benefits would the code above have over something like this:</p>
  
  <pre><code>try{
        //use buffering
        InputStream file = new FileInputStream("quarks.ser");
        InputStream buffer = new BufferedInputStream(file);
        ObjectInput input = new ObjectInputStream (buffer);
        List&lt;String&gt; recoveredQuarks = (List&lt;String&gt;)input.readObject();
        for(String quark: recoveredQuarks){
            System.out.println("Recovered Quark: " + quark);
        }
        input.close();
  } catch(ClassNotFoundException ex){
        //some exception handling
  }
  </code></pre>