import com.opencsv.CSVReader; import java.io.FileReader; import java.util.ArrayList; import java.util.List; public class Person { private String name; private int age; } public class CSVReaderExample { public static void main(String[] args) { List<Person> persons = new ArrayList<>(); try (CSVReader reader = new CSVReader(new FileReader("data.csv"))) { String[] nextLine; while ((nextLine = reader.readNext()) != null) { Person person = new Person(); person.setName(nextLine[0]); person.setAge(Integer.parseInt(nextLine[1])); persons.add(person); } } catch (Exception e) { e.printStackTrace(); } } }


上一篇:
下一篇:
切换中文