我正在尝试使用 opencsv 传递一个 csv 文件。该 csv 文件有三列 (,)。如何使用各自的值将每一行解析为我的数组列表?请参阅下面的代码。
public class Customer {
private String accNum;
private String fName;
private String lName;
public Customer(String accNum, String fName, String lName) {
this.accNum = accNum;
this.fName = fName;
this.lName = lName;
}
//getters & setters
...
}
public class CustomerList{
public void getCustList(File file) throws IOException {
List <Customer> custList = new ArrayList <Customer>();
CSVReader reader = new CSVReader (new FileReader (file));
String [] header = reader.readNext();
List<String[]> cList = reader.readAll();
for (int i =0 ; i < cList.size(); i++)
{
String[] line = cList.get(i); //not sure how to do this
for (String list: line)
{
custList.add( new Customer (list));// constructor takes three arguments
}
}
}