Write to File After Closing
As part of an assignment, I have to write to a file after my JFrame component closes. Right now, it will write to a file regardless of its visibility. Here is my write method:
Code:
public static void write(String text){
FileWriter fw = null;
PrintWriter pw = null;
try{
fw = new FileWriter("updated_contacts.txt", true);
pw = new PrintWriter(fw);
pw.println(text);
pw.close();
}catch (IOException e){
JOptionPane.showMessageDialog(null, "File 'updated_contacts.txt' not found.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
I also have an actionPerformed method, but this simply calls the method above with a string as its parameter. Nonetheless, I will provide the code if requested.
Thanks.
Ben