I am trying to get a code that takes a csv file and puts it into an ArrayList and shows the content of the ArrayList. I believe I have the code correct for getting the data into the ArrayList but I can't get it to print. Please any advice is welcome. I am very new to Java and coding in general.
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
class Employee{
public String FirstName;
public String LastName;
public String Company;
public String Address;
public String City;
public String County;
public String State;
public String Zip;
public String Phone;
public String Fax;
public String Email;
public String Web;
}
public class ITCO321IPWeek4 {
public static void main(String[] args) throws FileNotFoundException, IOException {
String line = "";
ArrayList <Employee> ALEmployee = new ArrayList();
FileReader fr = new FileReader("C:\\Users\\User\\Downloads\\ITCO321_U4IP_sample_data.csv");
try (BufferedReader br = new BufferedReader(fr)) {
while ((line = br.readLine())!=null){
Employee emp = new Employee();
String[] empFields = line.split(",");
emp.FirstName = empFields[0];
emp.LastName = empFields[1];
emp.Company = empFields[2];
emp.Address = empFields[3];
emp.City = empFields[4];
emp.County = empFields[5];
emp.State = empFields[6];
emp.Zip = empFields[7];
emp.Phone = empFields[8];
emp.Fax = empFields[9];
emp.Email = empFields[10];
emp.Web = empFields[11];
ALEmployee.add(emp);
}
}
}
}