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:
- Git stash temporary storage recovery and file deletion recovery
- Java class file operation and exception
- Solution to “550 create directory operation failed” in FTP operation file
- Failed to write output file ‘C:’ windows\ Microsoft.NET \Framework64\v4.0.30319\Temporary ASP.NET Files\root\106f9ae8\cc0e1
- Python read / write file error valueerror: I/O operation on closed file
- HDFS Java API operation error (user permission)
- java.net.SocketException: socket failed: EPERM (Operation not permitted)
- Java retainAll throws an unsupported operation exception record
- Solving the problem of can’t create temporary directory of CVS under Windows
- Java – read all the files and folders in a certain directory and three methods to get the file name from the file path
- Error in downloading update creation environment of CONDA: collecting package metadata (current_ repodata.json): failed
- How to solve the “specified service has been marked for deletion” error
- An error is reported during Java operation due to the problem of static resource export
- Creation and use of Oracle sequence
- 451 4.7.0 temporary server error. Please try again later. Prx5
- Linux error deletion libc.so.6 how to recover
- Gephi pop up JVM creation failed
- Windows encountered 1152 when installing software: error extracting files to the temporary location
- Pychar oserror: [winerror 1455] the page file is too small to complete the operation.
- PHP function file_ get_ Contents() reports an error when using HTTPS protocol: SSL operation failed