Results 1 to 2 of 2
  1. #1
    safwa_man is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default GUI to save to file

    Greetings Gents,

    I am new in this professional forums and I would like to help me !!

    I am trying to created interface to save input data to file. Interface done however I am facing problem with saving data to file every time it save over old one.

    code I am using


    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {




    try
    {


    PrintWriter fileOut = new PrintWriter(new FileWriter("filename.txt"));
    fileOut.append(jTextField1.getText());
    fileOut.append(jTextField2.getText());
    fileOut.append(jTextField3.getText());
    fileOut.append(jTextField4.getText());
    fileOut.append(jTextField5.getText() );

    fileOut.close(); // Close the output stream after all output done.

    JOptionPane.showMessageDialog(null, "Student record saved seccussecfully !!");
    jTextField1.setText("");
    jTextField2.setText("");
    jTextField3.setText("");
    jTextField4.setText("");
    jTextField5.setText("");
    }
    catch (IOException ioe)
    {
    System.out.println("Exception ");
    }
    // TODO code application logic here

    return;



    I need output like

    Fname/lastname/Telephone/ID/addree

    Fname/lastname/Telephone/ID/addree

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: GUI to save to file

    Please use [code] tags [/code] when posting code.
    Look at the available constructors for FileWriter.
    One of them allows you to append.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. Java save to file / open from file - trouble
    By joelBeaton in forum Advanced Java
    Replies: 6
    Last Post: 03-23-2012, 12:47 PM
  2. Replies: 3
    Last Post: 06-21-2011, 04:51 PM
  3. save file based on file extension
    By masa in forum AWT / Swing
    Replies: 4
    Last Post: 05-11-2010, 11:17 AM
  4. Replies: 0
    Last Post: 03-05-2010, 04:21 AM
  5. Save file
    By dejos456 in forum New To Java
    Replies: 4
    Last Post: 11-28-2009, 03:13 PM

Posting Permissions

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