Assuming you have imported CSV with OpenCSV libraryt to your project, you can read the CSV files like how my team implemented it:
public class CSVReader {
public static void addCardsFromCSVFile(File csvFile) throws CsvValidationException, IOException {
// Initialize CSV reader
CSVReader reader = new CSVReaderBuilder(new FileReader(csvFile)).build();
// Array to hold each line of the CSV file
String[] nextLine;
// Iterate through each line in the CSV file
boolean isFirstLine = true;
while ((nextLine = reader.readNext()) != null) {
// Skip the first line if it contains headers
if (isFirstLine) {
isFirstLine = false;
} else {
// Create a Card object from the CSV data
Card card = new Card(nextLine);
// add it to a data structure
}
}
// Optionally, return the HashMap or perform other actions
}