title: Why are parentheses needed for try/catch block BufferedWriter
body: <p>I'm writing some code using java.io.BufferedWriter
  the first thing I tried was:</p>
  
  <pre><code>    String filename = new String("test.txt");
      Charset charset = new Charset("US-ASCII");
      try {
          BufferedWriter bw = Files.newBufferedWriter(Paths.get(filename), charset);
          bw.write("hello");
      } catch (IOException e) {
          System.out.println(e);
      }
  </code></pre>
  
  <p>which outputted an empty test.txt
  seeing an example, in the following format, I tried:</p>
  
  <pre><code>    String filename = new String("test.txt");
      Charset charset = new Charset("US-ASCII");
      try (BufferedWriter bw = Files.newBufferedWriter(Paths.get(filename), charset)){
          bw.write("hello");
      } catch (IOException e) {
          System.out.println(e);
      }
  </code></pre>
  
  <p>which outputted a text file with the first line "hello".
  What does this form mean, and why does it work while my first attempt did not?</p>