title: Open and Close of same File multiple times vs Opening File for long time
body: <p>I am writing to a <code>File</code> whenever any change of content in <code>JTextArea</code> field.I have decided to open and close the file content each time as per the change event.</p>
  
  <p>Something like ,</p>
  
  <pre><code>public void addToLogFile(String changeContent) {
      try {
          PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(currentLogFile,true)));
          pw.print(changeContent);
          pw.close();
      } catch (FileNotFoundException ex) {
          Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
      } catch (IOException ex) {
          Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
      }
  }
  </code></pre>
  
  <p>Instead of opening and closing the file each time, I thought may be we could open it at initial phase and dump content whenever required. Finally close it at the end phase. </p>
  
  <p><strong>At Initial Phase of program:</strong></p>
  
  <pre><code>PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(currentLogFile,true)));
  </code></pre>
  
  <p>Then somewhere in code, wherever needed, </p>
  
  <pre><code>pw.print(changeContent); // Most frequent usage
  </code></pre>
  
  <p><strong>At Final Phase of program:</strong></p>
  
  <pre><code>pw.close();
  </code></pre>
  
  <p>Which one will be more efficient ? Under what condition, Do I have to choose one ? </p>