gpt4 book ai didi

java - File.createTempFile 检查文件是否存在?

转载 作者:行者123 更新时间:2023-11-30 06:19:06 26 4
gpt4 key购买 nike

如果我用这个方法,碰巧有一个同名的临时文件,这个文件被覆盖了?我说的是一个会在很长一段时间内生成许多临时文件的应用程序。

最佳答案

来自 createTempFile ( here ) 上标记为 2 的 JavaDoc,

Neither this method nor any of its variants will return the same abstract pathname again in the current invocation of the virtual machine.

编辑

返回部分说

An abstract pathname denoting a newly-created empty file

而且,它进一步指出

Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name. If this method returns successfully then it is guaranteed that: The file denoted by the returned abstract pathname did not exist before this method was invoked

关于java - File.createTempFile 检查文件是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23696415/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com