Temporary file is used to store the less important and temporary data, which should always be deleted when your system is terminated. The best practice is use the File.deleteOnExit() to do it.
File temp = File.createTempFile("abc", ".tmp");
The above example will create a temporary file named “abc.tmp” and delete it when the program is terminated or exited.
If you want to delete the temporary file manually, you can still use the File.delete().
public class DeleteTempFileExample
public static void main(String args)
//create a temp file
File temp = File.createTempFile("temptempfilefile", ".tmp");
//delete temporary file when the program is exited