groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Søren Berg Glasius <soe...@glasius.dk>
Subject Re: what's the difference?
Date Fri, 07 Aug 2015 11:30:24 GMT
That's because it's two different ways of doing the same thing. The first
is just more compact, and does not give you access to the reader, where as
the second gives you access to the reader and allows you to do various
things with it.


Best regards / Med venlig hilsen,
Søren Berg Glasius

Hedevej 1, Gl. Rye, 8680 Ry, Denmark
Mobile: +45 40 44 91 88, Skype: sbglasius
--- Press ESC once to quit - twice to save the changes.

On 7 August 2015 at 12:53, Mauro Sanna <mrsanna1@gmail.com> wrote:

> It's not clear to me what's the difference between:
>
> file1.eachLine() { println it }
>
> and
>
> file1.withReader { reader ->
>     while ((line = reader.readLine()) != null) {
>         println line
>     }
> }
>
> the output is the same.
> Thank you.
>

Mime
View raw message