У меня есть текстовый файл с датой, именем, описанием и суммой.
10/10/2018, Gel, Hair Product, 2000.00
С помощью введенного мной кода пользователь может ввести новую строку в исходный текстовый файл:
public static void recordExpense(String filename)throws IOException{
String expense = "";
String date = "";
String description = "";
double amount = 0.0;
PrintWriter pw = null;
try {
pw = new PrintWriter(new BufferedWriter(new FileWriter(filename,true)));
date = readDate(); //user enters the date
expense = readExpense(); //user enters the name of the expense
description = readDescription(); // user enters the description of the expense
amount = readAmount(); .//user enters how much it costs
pw.println(date+", "+expense+", "+description+", "+amount);
pw.close();
}catch (Exception e){
System.out.println("The file could not be found");
}
}
Вместо ожидаемого результата, например:
10/10/2018, Gel, Hair Product, 2000.00
11/10/2018, Comb, Stuff, 20.00
Вместо этого получилось бы следующее:
10/10/2018, Gel, Hair Product, 2000.0011/10/2018, Comb, Stuff, 20.00
Как это исправить?