help with JButton and writing to a text file
i will post the entire code if requested, but i want to focus on this bit:
public void actionPerformed(ActionEvent arg0)
{
fw = new FileWriter("G:\\FINAL PROJECT\\program\\list.txt");
list = new PrintWriter(fw);
String word = wordField.getText();
String definition = defArea.getText();
list.output(word + "\t" + definition);
list.close();
fw.close();
}
where do throw the IOException in order for this code to work properly?
what im trying to do here is to add a word and its definition to a text file(list.txt) when a button is clicked
Re: help with JButton and writing to a text file
There's nowhere you could put any exception handling in that code and have it work properly. Check the PrintWriter API to see what methods it has available.
Re: help with JButton and writing to a text file
Why do you want to throw the exception? Place a try/catch statement around the line(s) of code that might throw an exception and handle them appropriately.