title: Getting input from TextArea and appending the input to existing .txt file
body: <p>I have created a java fxml and a corresponding controller class. </p>
  
  <p>In my controller class I have:</p>
  
  <pre><code>@FXML
  private TextArea addBox;
  @FXML
  private Button addButton;
  </code></pre>
  
  <p>I also have a 'add' button with a attached method called addButton, so when 'add' button is pressed input from TextArea is added to my existing Data.txt file I have tried:</p>
  
  <pre><code> private void addButton(ActionEvent event) throws IOException {
     Writer output;
     output = new BufferedWriter(new FileWriter("Data.txt", true));
     output.append(addBox.getText());
     output.close();
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>    @FXML
  private void addButton(ActionEvent event) throws IOException {
     try(FileWriter fw = new FileWriter("Data.txt", true);
  BufferedWriter bw = new BufferedWriter(fw);
  PrintWriter out = new PrintWriter(bw))
   {
  out.println(addBox.getText());
  
  
  } catch (IOException e) {
  
  }
  </code></pre>
  
  <p>Similarly,if I put John into TextArea(addBox) and click 'delete' button it should delete a row(s) that has the word John in it. I can't get these two methods to work. Is there something wrong with AddBox.getText();? shouldn't it get the input and treat it like String?</p>
  
  <pre><code>@FXML
  private void deleteButton(ActionEvent event) throws FileNotFoundException, IOException {
      File inputFile = new File("Data.txt");
      File tempFile = new File("myTempFile.txt");
  
      BufferedReader reader = new BufferedReader(new FileReader(inputFile));
      BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
  
      String lineToRemove = addBox.getText();
      String currentLine;
  
      while ((currentLine = reader.readLine()) != null) {
          // trim newline when comparing with lineToRemove
          String trimmedLine = currentLine.trim();
          if (trimmedLine.equals(lineToRemove)) {
              continue;
          }
          writer.write(currentLine + System.getProperty("line.separator"));
      }
      writer.close();
      reader.close();
      boolean successful = tempFile.renameTo(inputFile);
  }
  </code></pre>
  
  <p>It seems to me that there aren't any syntax errors as it runs without errors. However, it won't add anything to existing .txt file. </p>