public void readCases(String filename) throws IOException {
records.clear(); //name of list is records
try (Scanner input = new Scanner(new File(filename))){
input.nextLine();
while (input.hasNext()){
String text = input.nextLine();
String[] element = text.split(",");
for(int i = 0; i<=3; i++){
if(element[i].equals(' ')){
throw new DatasetException("column missing in csv");
}
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-uuuu");
LocalDate date = LocalDate.parse(element[0], formatter);
int europeCases = Integer.parseInt(element[1]);
int asiaCases = Integer.parseInt(element[2]);
int africaCases = Integer.parseInt(element[3]);
CaseRecord caseRecord = new CaseRecord(date, europeCases, asiaCases, africaCases);
addRecord(caseRecord); //this adds caseRecords to records
}
}
}
I am trying to clear an old list, then trying to read a CSV file and loading the list into the list. I'm not really sure where I'm going wrong. The list contains 4 fields with types
- DateTime
- int
- int
- int
and is in the form
2020-10-08,4,41,0
The top line reads
Date,Europe,Asia,Africa
and I want to skip this first line when loading the data into the list.