title: Disadvantages of Java try-with-resources
body: <p>I have a method which loads a file into a reader. Tests or other code can use this reader to read the file. The problem is that I cannot declare the reader outside of the try-with-resources/TWR block. Is this a disadvantage of TWR or am I missing something ?</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.FileReader;
  import java.io.IOException;
  
  public class TestngTesting {
      BufferedReader fileReader;//Can't declare this as final, because its not assigned here itself.
      BufferedReader fileReader1;
  
      //Can be made @BeforeClass method.
      public void loadFile() throws IOException {
          fileReader = new BufferedReader(new FileReader("path/file.txt"));
  
          //Compile error - Variable used as a try-with-resources resource should be final or effectively final.
          try(fileReader){
  
          }
  
          try{
              fileReader1 = new BufferedReader(new FileReader("path/file.txt"));
          }finally {
              //end gracefully.
          }
      }
  }
  </code></pre>
  
  <p>PS - I read these two posts before posting my question - <a href="https://stackoverflow.com/questions/22663403/using-resources-of-try-with-resources-outside-try">link</a>, <a href="https://stackoverflow.com/questions/44990800/using-preparedstatement-in-try-with-resources-shows-unknown-class-error">link</a>.</p>