title: java try finally block to close stream
body: <p>I want to close my stream in the finally block, but it throws an <code>IOException</code> so it seems like I have to nest another <code>try</code> block in my <code>finally</code> block in order to close the stream. Is that the right way to do it? It seems a bit clunky.</p>
  
  <p>Here's the code:</p>
  
  <pre><code> public void read() {
      try {
          r = new BufferedReader(new InputStreamReader(address.openStream()));
          String inLine;
          while ((inLine = r.readLine()) != null) {
              System.out.println(inLine);
          }
      } catch (IOException readException) {
          readException.printStackTrace();
      } finally {
          try {
              if (r!=null) r.close();
          } catch (Exception e){
              e.printStackTrace();
          }
      }
  
  
  }
  </code></pre>