在我的程序中,我有一个显示按钮。一旦我点击它,信息就会显示并保存到文件中。
到目前为止,这是我的代码:
public void LoadFromFile(){
FileWriter writer;
try{
writer = new FileWriter(fileName1, true);
writer.write("Manager: "+Manager + System.getProperty("line separator "));
writer.write("\nSortCode: "+SortCode + System.getProperty("line separator "));
writer.write("\nWorkingHours: "+WorkingHours + System.getProperty("line separator "));
writer.write("\nHouse No: "+LoadFromFile.getHouse_no()+System.getProperty("line separato " ));
writer.write("\nHouse Name: "+LoadFromFile.getHouseName()+System.getProperty("line separator "));
writer.write("\nStreet: "+LoadFromFile.getStreet()+System.getProperty("line separator "));
writer.write("\nTown: "+LoadFromFile.getTown()+System.getProperty("line separator "));
writer.write("\nCountry: "+LoadFromFile.getCountry()+System.getProperty("line separator "));
writer.flush();
writer.close();
writer = null;
}catch(IOException ioe){
}
}
在我的程序中,我有一个保存按钮,因此当我编辑信息并保存时,它将更改并显示新信息。
然而,它只是将旧信息复制到文件而不是新文件中。
public void SaveToFile(){
FileWriter writer;
try{
writer = new FileWriter(fileName1, true);
writer.write("Manager: "+Manager + System.getProperty("line separator"));
writer.write("\nSortCode: "+SortCode + System.getProperty("line separator"));
writer.write("\nWorkingHours: "+WorkingHours + System.getProperty("line separator"));
writer.write("\nHouse No: "+SaveToFile.getHouse_no()+System.getProperty("line separator"));
writer.write("\nHouse Name: "+SaveToFile.getHouseName()+System.getProperty("line separator"));
writer.write("\nStreet: "+SaveToFile.getStreet()+System.getProperty("line separator"));
writer.write("\nTown: "+SaveToFile.getTown()+System.getProperty("line separator"));
writer.write("\nCountry: "+SaveToFile.getCountry()+System.getProperty("line separator"));
writer.flush();
writer.close();
writer = null;
}catch(IOException ioe){
}
}