I have this code that prints values in a text field to a file. But how would I adapt my code to append text repeatedly to an existing file in Java.
JButton submitInvoice = new JButton ("Submit");
sPanel.add(submitInvoice);
submitInvoice.addActionListener(e8->{
try{
BufferedWriter bw = new BufferedWriter(new FileWriter("RegInvoice_0to2.txt",true));
bw.write("---------------Booking Invoice---------------");
bw.write("\r\n");
bw.write("All Day: "); bw.write(tSesh1.getText());
bw.write("\r\n");
bw.write("Morning: "); bw.write(tSesh2.getText());
bw.write("\r\n");
bw.write("Lunch: "); bw.write(tSesh3.getText());
bw.write("\r\n");
bw.write("Afternoon: "); bw.write(tSesh4.getText());
bw.write("\r\n");
bw.write("Pre School: "); bw.write(tSesh5.getText());
bw.write("\r\n");
bw.write("Full Holiday Care: "); bw.write(tSesh6.getText());
bw.write("\r\n");
bw.write("----------------Total Amount----------------");
bw.write("\r\n");
bw.close();
}catch(Exception ex){
ex.printStackTrace();
}
});