Results 1 to 3 of 3
  1. #1
    tom2zip is offline Member
    Join Date
    Nov 2011
    Rep Power

    Default 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);


    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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default 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.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Rep Power

    Default 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.

Similar Threads

  1. Replies: 2
    Last Post: 09-05-2011, 12:38 AM
  2. Replies: 8
    Last Post: 07-17-2011, 02:38 PM
  3. Error in writing JButton Array of objects into File
    By justbeller in forum AWT / Swing
    Replies: 3
    Last Post: 06-08-2011, 11:06 PM
  4. Writing Text To A File
    By loopsnhoops in forum New To Java
    Replies: 15
    Last Post: 06-01-2011, 03:27 AM
  5. Replies: 1
    Last Post: 02-27-2010, 01:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts