Read large CSV in java

Read line by line something like this CSVReader reader = new CSVReader(new FileReader(“yourfile.csv”)); String [] nextLine; while ((nextLine = reader.readNext()) != null) { // nextLine[] is an array of values from the line System.out.println(nextLine[0] + nextLine[1] + “etc…”); }

OpenCSV – How to map selected columns to Java Bean regardless of order?

You can use HeaderColumnNameTranslateMappingStrategy. Lets assume your CSV has the following columns: Id, Fname, Telephone, Lname, Address for the sake of simplicity. CsvToBean<Person> csvToBean = new CsvToBean<Person>(); Map<String, String> columnMapping = new HashMap<String, String>(); columnMapping.put(“Id”, “id”); columnMapping.put(“Fname”, “fname”); columnMapping.put(“Lname”, “lname”); HeaderColumnNameTranslateMappingStrategy<Person> strategy = new HeaderColumnNameTranslateMappingStrategy<Person>(); strategy.setType(Person.class); strategy.setColumnMapping(columnMapping); List<Person> list = null; CSVReader reader = new … Read more