用Java创建一个指定的临时文件 [英] Create a named temp file in Java

查看:186
本文介绍了用Java创建一个指定的临时文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在Java中创建一个临时文本文件来显示在屏幕上,但是使用File.createTempFile()不能给我足够的控制权。

这里有什么想法?

解决方案

在临时文件的名称?



除了这个问题,不能完全控制由生成的文件的名称createTempFile 。如果你真的需要完全控制,你需要创建一个普通的文件



你可能想要使用


  • java.io.tmpdir 临时文件目录的系统属性

  • createNewFile()检查命名冲突
  • deleteOnExit ()


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()

这篇关于用Java创建一个指定的临时文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆