I was wondering if there is any neat way to write new line into the file from Groovy. I have the following script:
new File("out.txt").withWriter{ writer ->
for(line in 0..100) {
writer << "$line"
}
}
I could use writer << "$line\n"
or writer.println("$line")
, but I was wondring if there is any way to use <<
operator to append the new line for me.
It's a nice idea to ask the system for the correct line separator as these can change between operating systems.
writer << "Line 1" + System.getProperty("line.separator") + "Line 2"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With