0

hello
i'm trying to code 'Save Button' which saves all the information in a file
this is what I did:

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

    java.io.File file=new java.io.File("File.txt");


        try {
            java.io.PrintWriter output = new java.io.PrintWriter(file);
            output.print(this.DateObject.getText());
            output.print(this.NoteObject.getText());


            output.close();
        } catch (FileNotFoundException ex) {
            System.out.println("");
        }


}                         

the problem is if I try to save new information in the same file it will delete the previous file and creat a new one meaning all previous information will be deleted
how can I fix that?
what I want to do is simply everytime I click save button it should save the new information in same file ...
and I'm building my GUI using GUI builder so i'm not coding to add buttons and all that stuff
thank you

2
Contributors
1
Reply
8
Views
4 Years
Discussion Span
Last Post by mvmalderen
1

Open your file in append mode:

PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.