-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustodialWriter.java
More file actions
27 lines (26 loc) · 1.31 KB
/
Copy pathCustodialWriter.java
File metadata and controls
27 lines (26 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.io.FileWriter;
import java.io.IOException; //In case of file errors//
import java.util.ArrayList;
public class CustodialWriter {
private final String csvFile = "custodialAccounts.csv";
public void addToCSV(Custodial account) {
try(FileWriter appender = new FileWriter(csvFile, true)) {
String dataString = account.getAccountNumber() + "," + account.getAccountCreationDate() + "," + account.getMinorAge() + "," + account.getBalance() + "\n";
appender.write(dataString);
}
catch(IOException e) {
System.out.println("Error occurred adding to file: " + e.getMessage());
}
}
public void saveData(ArrayList<Custodial> accounts) {//still working on this method, it should overwrite the file with the new data from the accounts arraylist//
try(FileWriter writer = new FileWriter(csvFile)) {
for (Custodial account : accounts) {
String dataString = account.getAccountNumber() + "," + account.getAccountCreationDate() + "," + account.getMinorAge() + "," + account.getBalance() + "\n";
writer.write(dataString);
}
}
catch(IOException e) {
System.out.println("Error occurred saving data to file: " + e.getMessage());
}
}
}