I'm having problems with saving text to a file, I'm saving text from text fields to a file. The text fields are saving to the file fine, but when I close the program re-open it and try to save a new entry, it wipes the file and corrupts it. Help would be greatly appreciated :)
// BUTTON SAVE ------------------------------------------
if(e.getSource() == btnSave)
{
// Call the saveEntry method that will copy the current
// TextField entries from the screen to the current
// record in the array in memory.
saveEntry(currentEntry);
}
public void saveEntry(int i) //
{
PersonsInfoData[i].setPersonsInfo(txtPersonsName.getText(),txtLikes.getText(),txtDislikes.getText(), txtBdayDay.getText(), txtBdayMonth.getText());
// You may also wish to write all the records that are currently in the array
// to your data file on the hard drive (USB, SSD, or equivalent)
writeFile(dataFileName);
}
public void writeFile(String fileName)
{
try
{
PrintWriter printFile = new PrintWriter(new FileWriter("BirthdayTracker.txt"));
for(int i = 0; i < numberOfEntries; i++)
{
printFile.println(PersonsInfoData[i].getPersonsName() + "," + PersonsInfoData[i].getPersonsLikes() + "," + PersonsInfoData[i].getPersonsDislikes() + "," + PersonsInfoData[i].getBdayDay() + "," + PersonsInfoData[i].getBdayMonth() );
}
printFile.close();
}
catch (Exception e)
{
System.err.println("Error Writing File: " + e.getMessage());
}