Java operation temporary file creation and deletion

in Java’s File class, there is a createTempFile(String prefix,String suffix) that is called to create a temporary File in the system’s default temporary File directory.
prefix means filename.
suffix represents the suffix of a file, in the form “. TMP “, note that “. “

is needed

final File htmlFile = File.createTempFile("temp", ".html");//创建临时文件
logger.info("临时文件所在的本地路径:" + htmlFile.getCanonicalPath());
FileOutputStream fos = new FileOutputStream(htmlFile);
try {
   //这里处理业务逻辑
} finally {
    //关闭临时文件
    fos.flush();
    fos.close();

    htmlFile.deleteOnExit();//程序退出时删除临时文件
}

on win7, the default directory for temporary files is C:\Users\Administrator\AppData\Local\Temp. After
finishes using the temporary file, executing htmlfile.deleteonexit () will automatically delete the temporary file.

Read More: