Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Tuesday 18 September 2018

Read csv file

                            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