Creating a temporary file

Making an existing file temporary this will delete the file on programm termination.

new File("test.txt").deleteOnExit()

Create a temporary file tmp.dat in the system tempory directory which will be deleted upon exit.

File tmp = File.createTempFile("tmp",".dat")
tmp.deleteOnExit()