I'm helping a colleague get to grips with Groovy scripting in Jenkins, and had introduced him to the "Sandbox"
I also wanted to provide some file I/O examples, as per the following: -
File greetingsFile = new File('/tmp/greetings.txt')
greetingsFile.write "Hello World!\n"
greetingsText = greetingsFile.getText('UTF-8')
println("Greeting is " + greetingsText)
All that does is (a) create a file containing the immoral phrase "Hello World!" and (b) read the content of the newly created file into a variable called greetingsText and (c) output the message to the console.