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:
- Record the location and cleaning of chrome junk files under appdata of Disk C
- [Python] failed building wheel for MySQL Python solution
- Rstudio drawing problem
- VMware uninstall installation problem (The MSI Failed)
- Error: Microsoft Visual C + + 14.0 is required. Get it with “Microsoft Visual C”++
- Gms2 (gamemaker Studio 2) running problems encountered in the project
- JOM error 2 problem when qtcreator uses cmake to build a project
- Visual Studio 2005 — Error code 1603 for this component means “Fatal error during installation.
- How to Fix Error in python3 | PIP install Dlib
- Solution of modulenotfounderror in running pychar
- Error: The size of the connection buffer (131072) was not large enough
- Solving the problem of can’t create temporary directory of CVS under Windows
- Error in installing paddlenlp on pip on Windows
- Pull code execution NPM install error code: 128
- [unity] when using unity hub, there is a problem of “failed to delete old unit installation file…” problem
- Failed to write output file ‘C:’ windows\ Microsoft.NET \Framework64\v4.0.30319\Temporary ASP.NET Files\root\106f9ae8\cc0e1
- Python SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3:
- raise HTTPError(req.full_url, code, msg, hdrs, fp)urllib.error.HTTPError: HTTP Error 404: Not Found
- After unity connects with androidstudio, unity packages APK with an error: commandinvocationfailure: failed to re package resources
- Error: EACCES: permission denied, access ‘/usr/local/lib/node_modules’ npm ERR! at Error (native)