Read csv file in grails
Add CsvGrailsPlugin
This plugin adds dynamic methods 'eachCsvLine' to each of the
following classes:- java.lang.String
- java.io.File
- java.io.InputStream
- java.io.Reader
Example-
def csvReader(){
def filePath="C:\\Users\\Ram\\Downloads\\Client & Fee charge.csv"
int i = 0;
new File(filePath1).eachCsvLine { tokens ->
if (i == 0) {
i = i + 1;
return }
i = i + 1;
def rollNumber = Integer.parseInt(tokens[0]);
def studentName = tokens[1];
def marks = Integer.parseInt(tokens[2]);
println rollNumber+" "+ studentName+" "+marks
}
No comments:
Post a Comment