examples/groovy/temp_file.gvy

File.createTempFile("temp",".tmp").with {
   //deleteOnExit()  // Including this line will cause the temp file to be deleted automatically

   write "Hello world"    // write to the temp file
   println absolutePath   // This is the path to the file
}

examples/groovy/temp_file_oop.gvy

File tf = File.createTempFile("temp",".tmp")
tf.write("Hello world")   // write to the file
println(tf.absolutePath)  // path to the file
tf.delete()               // delete the file