开发者

Create a named temp file in Java

开发者 https://www.devze.com 2022-12-22 13:01 出处:网络
I want to be able to create a temporary text File in Java to display on screen, but using File.createTempFile() does not give me enough control over 开发者_开发技巧its name.

I want to be able to create a temporary text File in Java to display on screen, but using File.createTempFile() does not give me enough control over 开发者_开发技巧its name.

Any thoughts here?


Why do you need such control over the name of a temporary file?

That question aside, no you can't have full control over the name of the file generated by createTempFile. If you really need full control, you need to create a regular File instead.

You may want to make use of the following:

  • java.io.tmpdir System property for temporary file directory
  • createNewFile() to check for naming conflicts
  • deleteOnExit()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号