I've got my code to read and write to text files, but when I try to save to the file, it just makes a blank one. Not sure what's causing this. Any help would be appreciated, as I'm sure I've overlooked something really simple. I know my code is messy and not nice, but I tried to work with as many new things as I could on this project and I've already learned a ton, so the next one will be better. I also know there are many improvements to be made, but I want to keep my original base so I can see how I improve from project to project.
here is full code: https://pastebin.run/gn-h-5njjdh7
and here are the snippets that are used to read/write.
static void ReadFromFile(ArrayList<String> contactList) {
try {
FileReader readFileContact = new FileReader("ContactList.txt");
BufferedReader readContact = new BufferedReader(readFileContact);
String tempContact;
while ((tempContact = readContact.readLine()) != null) {
contactList.add(tempContact);
}
}catch (IOException e) {
e.printStackTrace();
}
}```
```java
static void WriteToFile(ArrayList<String> contactList) {
try {
FileWriter writeFileContact = new FileWriter("ContactList.txt");
BufferedWriter writeContact = new BufferedWriter(writeFileContact);
for (String contact : contactList) {
writeContact.write(contact);
}
} catch (IOException e) {
e.printStackTrace();
}
}```
cant paste the rest but I use `WriteToFile` at the end of add,edit,delete and exit. Meaning it first runs my normal code to perform the action and then I added `WriteToFile();`.
Like this.
```java
case 1:
addContact(contactList, scanner);
WriteToFile(contactList);
break;```
/**
Need to add persistent storage for contactList
**/
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new…