//planet.csv Star,Constellation,Age (Gyr) HD 142,Phoenix,5.931 WASP-44,Cetus,0.911 WASP-32,Pisces,4.728
@Test public void read_CSV_File_With_OpenCSV () { InputStream in = this.getClass().getClassLoader().getResourceAsStream("planets.csv"); try { CSVReader reader = new CSVReader(new InputStreamReader(in), '\t'); List<String[]> rows = reader.readAll(); for (int x=0; x < rows.size(); x ++) { String[] columns = rows.get(x); for (int y=0; y < columns.length; y++) { logger.info(columns[y]); } } } catch (FileNotFoundException e) { logger.error(e); } catch (IOException e) { logger.error(e); } }
Output
Star,Constellation,Age (Gyr) HD 142,Phoenix,5.931 WASP-44,Cetus,0.911 WASP-32,Pisces,4.728