I am having problem appending data to already existing .txt file. I have created a TextArea using:
@FXML
private TextArea addBox;
Then created a following method in attempt to add input from TextArea(addBox) to my existing .txt file when 'add' button is clicked. The method works, however it overwrites my .txt file. It will delete everything I have in my .txt file and update it when 'add' button is clicked. Is there anyway I can append input I received from TextArea to my .txt file while keeping my old data? Thank you for your time.
{
@FXML
private void addButton(ActionEvent event) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append(addBox.getText().toString());
File file = new File("src/javafxapplication2/Data.txt");
FileWriter w = new FileWriter(file);
w.write(sb.toString());
w.close();
}