Posted By

theroamingcoder on 03/04/10


Tagged

csv groovy opencsv


Versions (?)

Groovy Read CSV File


 / Published in: Groovy
 

To use, first add the opencsv .jar to .groovy/lib.

  1. import au.com.bytecode.opencsv.CSVReader;
  2.  
  3. CSVReader reader = new CSVReader(new FileReader("categories.csv"));
  4. def number = 0
  5. while ((nextLine = reader.readNext()) != null) {
  6. // nextLine[] is an array of values from the line
  7. println number +":"+ nextLine[0] + "|" + nextLine[1] + "|" + nextLine[3]
  8. number ++
  9. }

Report this snippet  

You need to login to post a comment.