Hello.
I've written a simple program that will once read text into a file and then append some other text when it starts reading again. In other words, adding text to an already existing one. My program doesn't do that but instead it keeps overwriting the older text. How can I change it so it will keep older text but append new ones in new line.
Here is my code:
Scanner i = new Scanner(System.in);
Scanner d = new Scanner(System.in);
System.out.println("Updating information.....");
System.out.println("\nUsername: ");
String name = i.nextLine();
System.out.println("\nAppointment Day: ");
String day = i.nextLine();
System.out.println("\nStarting Time: ");
double start = d.nextDouble();
System.out.println("\nEnding Time: ");
double end = d.nextDouble();
System.out.println("\nNotes/Comments: ");
String note = i.nextLine();
File file = new File("C://Users/s11065250/Assig1-Client/src/Sample.txt");
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.append(name + " ");
bw.append(day + " ");
bw.append(String.valueOf(start) + " ");
bw.append(String.valueOf(end) + " ");
bw.append(note + " ");
bw.newLine();
bw.close();
System.out.println("\nInformation updated successfully");
Another question, what is the appropriate data type to be used for TIME such as starting time and ending time. I used double but I think there must be a better option.
Thanks.