Wednesday, 30 January 2019

Groovy: Read a file line by line


Below script prints all the content of a file line by line.

HelloWorld.groovy
String filePath = "C:\\Users\\Public\\data.json";
int totalLines=0

new File (filePath).eachLine { line ->
 totalLines++
 println "$line"
}

println "Total Lines Read : $totalLines"



Previous                                                 Next                                                 Home

No comments:

Post a Comment