Groovy: temporary file with autodelete
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
Published on 2018-10-30
Comments
In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation. comments powered by Disqus
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post