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");//创建临时文件"临时文件所在的本地路径:" + htmlFile.getCanonicalPath());
FileOutputStream fos = new FileOutputStream(htmlFile);
try {
} finally {


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: