I need help on figuring out how to send data to a file without it replacing the data and also repeating other data. The code below doesnt replace any darta, but it repeats data that i want in there (which i dont want replacing):
public void writeCustomerData() { try{ Frame owner = null; //Sets the owner of the file to null. FileDialog newFileDialog1 = new FileDialog(owner, "Open", FileDialog.SAVE); //Creates a fileDialog object. newFileDialog1.setVisible(true); //Chooses the file that will be read in. File newFile1 = new File(newFileDialog1.getFile()); if(customerMap.size()> 0) { for(Customer customers : customerMap.values()) { PrintWriter nw = new PrintWriter(new FileWriter(newFile1,true)); nw.print("ok"); customers.writeData(nw); nw.close(); } } else { System.out.println("No Customers In The List"); } } catch(FileNotFoundException a) { System.out.print("File cannot be found"); } catch(IOException a) { System.out.print("File cannot be found"); } }