I need a little help. I have a CSV file and I am reading it like this:
public class LectorDeArchivosCSV {
private List<Alumno> listaAlumnos;
public LectorDeArchivosCSV() {
listaAlumnos = new ArrayList<>();
}
public List<Alumno> getListaAlumnos() {
return listaAlumnos;
}
public static void leerCsv() {
CSVReader csvReader = null;
try {
/**
* Reading the CSV File
* Delimiter is comma
* Start reading from line 1
*/
csvReader = new CSVReader(new FileReader("listadoDeAlumnos.csv"), ',', '"', 1);
//employeeDetails stores the values current line
String[] alumnoDetails = null;
//List for holding all the rows
List<String[]> rows = new ArrayList<String[]>();
rows = csvReader.readAll();
//Read individual row from List of rows
for (String[] row : rows) {
System.out.println(Arrays.toString(row));
}
} catch (Exception ee) {
ee.printStackTrace();
} finally {
try {
//closing the reader
csvReader.close();
} catch (Exception ee) {
ee.printStackTrace();
}
}
}
This is how each row of the csv file looks
[1, Martin, Lopez]
The Integer being the Student code, String name and String last name. I need for each row to create an object of type Student with this data (I already have the constructor done).