title: How to ensure the closure of an I/O stream?
body: <p>Consider this function:</p>
  
  <pre><code>import java.io.IOException;
  import java.io.Reader;
  
  class StreamPrinter {
  
      void print(Reader reader) throws IOException {
          int code = reader.read();
          while (code != -1) {
              System.out.print((char) code);
              code = reader.read();
          }
  
          reader.close();
      }
  
  }
  </code></pre>
  
  <p>How to close the stream in case of exception and error?</p>