hey everyone,
well i got a little problem im trying to write input from the JTextField into the file (file4.txt) but the problem is it keeps overwriting the text file each time i make input and any data ther was is changed in to new data.all i need is that it would add the new information below the old information.
any suggestions?

public void actionPerformed(ActionEvent e) {
String nameText = enterName.getText();
try
    { 
      BufferedWriter bufewr;
      bufewr         = new BufferedWriter(new FileWriter("file4.txt"));
      for (int i=0; i<1; i++)
      { bufewr.write(nameText);
        bufewr.newLine();
        System.out.println("string= " + nameText);
      }

      bufewr.flush();
      bufewr.close();
    }
    catch(IOException e)
    { System.err.println("Exception: " + e.getMessage());
      System.exit(1);
    }
  }

any suggestion would be greatly appreciated
thank you

Open the file writer in append mode :
new FileWriter("file4.txt", true)

wow this was easy didn't expect that to be so simple thank you very much
thank YOU

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.