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

        } catch (FileNotFoundException ex) {


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

Open your file in append mode:

PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.