title: How do I code the function of the Save button in Java?
body: <p>I have an existing text file and edited some stuff in it. I want to save a line of text to that same file. Currently, my Save button will create a new file for the text file I just edited. What I want is that my Save button will just overwrite the existing file. What code do I need to write on it?</p>
  
  <p>Here's my current code:</p>
  
  <pre><code>private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {                                        
      JFileChooser fc = new JFileChooser();
  
      int choice = fc.showSaveDialog(null);
      if (choice == JFileChooser.APPROVE_OPTION) {
          String filename = fc.getSelectedFile().getAbsolutePath();
          writeToFile(filename);
      }
  }                                    
  </code></pre>
  
  <p>here's my writeToFile code:</p>
  
  <pre><code>       private void writeToFile(String filename) {
         Person p = getPersonFromDisplay();
         PersonFileMgr.save(filename, p);
     }
  </code></pre>