I am a beginner. I have a text file which already has data and the data can be updated but now i would like to add more data from another GUI form to be added at the end of the data
Now it look like this
name//add/password//postcode//email//hpNo//Buyer
I want to add one more item at the end of the row
name//add/password//postcode//email//hpNo//Buyer//PAYMENT
My current code creates a new data instead of adding it to the last column:
 String addcash="";
 try
 {
         File file = new File("MyAccount.txt");
         Scanner reader = new Scanner (file); 
         String line = "", oldtext = "", update = "";
         while(reader.hasNextLine())
         {
             line = reader.nextLine();
             String[] text = line.split("//");
             accNameTextField.setText(new User().getusername());
             if (text[0].equals(accNameTextField.getText())){
                  String update2 =  "//" + addcshComboBox.getSelectedItem(); 
                 addcash += accNameTextField.getText() + update2 + System.lineSeparator(); 
             }
             else
             {
                 addcash += line + System.lineSeparator();
             }
         }
         reader.close();
         FileWriter writer = new FileWriter("MyAccount.txt");
         writer.write(addcash);writer.close();
     }
     catch (IOException ioe)
     {
         ioe.printStackTrace();
     }
}
 
     
    