java中有没有生成临时文件的方法?

tenix 2004-12-28 11:06:02
java程序中需要生成一个临时文件,java中有没有这样的方法,指定一个路径,自动在路径下生成一个文件,和已有文件都不重名?
...全文
378 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
colin_lgh 2004-12-28
  • 打赏
  • 举报
回复
java.io.File类
static File createTempFile(String prefix, String suffix)
static File createTempFile(String prefix, String suffix, File directory)

Creates an empty file in the default temporary-file directory or in the specified directory, using the given prefix and suffix to generate its name. Invoking this method is equivalent to invoking createTempFile(prefix, suffix, null).

Parameters:
prefix - The prefix string to be used in generating the file's name; must be at least three characters long
suffix - The suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used
direcotory - The directory in which the file is to be created, or null if the default temporary-file directory is to be used

Returns:
An abstract pathname denoting a newly-created empty file
Throws:
IllegalArgumentException - If the prefix argument contains fewer than three characters
IOException - If a file could not be created
SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not allow a file to be created
Since:
1.2


Eraserpro 2004-12-28
  • 打赏
  • 举报
回复
有,java.io.File中的createTempFile(String prefix, String suffix)方法

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧