How do I iterate over all lines of files passed on the commandline in Groovy?

Posted by Shuja on Stack Overflow See other posts from Stack Overflow or by Shuja
Published on 2010-06-13T17:15:56Z Indexed on 2010/06/13 17:22 UTC
Read the original article Hit count: 147

Filed under:
|

Hi I want to read whole file contents in groovy on command line. I am using this code

#!/usr/bin/env groovy


   def xmlData =""

 System.in.withReader {

        xmlData=xmlData+ it.readLine()

} 

println xmlData

and the following command

cat 1.xml | /root/a.groovy

But it only reads one line from the file. I want to read whole file.

Any suggestion?? Regards Shuja

© Stack Overflow or respective owner

Related posts about file

Related posts about groovy