i have a file DataFile.txt with few records. when i am adding new entry, it clears all the other records and saving only new one. but i want to append that record.
private void saveFile()
{
try
{
PrintWriter out = new PrintWriter(new FileWriter("DataFile.txt"));
String name ="";
String ID="";
String roomType ="";
String meal="";
int days=0;
int tprice=0;
for (int i = 0; i < myList.size(); i++)
{
Customer c = myList.get(i);
name = c.getName();
ID = c.getID();
roomType = c.getRoomItem();
meal = c.getMealItem();
days = c.getDaysIndex();
tprice = c.getTotalPrice();
out.println(name + "," + ID+ "," + roomType+ "," + meal+ "," + days+ "," + tprice);
}
out.close();
JOptionPane.showMessageDialog(null,"Data saved successfully!","",
JOptionPane.INFORMATION_MESSAGE);
}
catch (Exception ex)
{
System.out.println("save file fail");
}
} //end of the method
thanks.