在 Java 中:在目录中创建唯一的随机文件名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2054078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In Java: create unique random filename in a directory
提问by Quintin Par
How do I create a random unique filename in a directory (of my choice)?
如何在(我选择的)目录中创建随机唯一的文件名?
Note:I don't want this file in the system temp path but rather in the directory I specify
注意:我不希望这个文件在系统临时路径中,而是在我指定的目录中
回答by cletus
File.createTempFile()allows you to specify a directory so:
File.createTempFile()允许您指定一个目录,以便:
File uniqueFile = File.createTempFile("post", ".html", new File("/var/www/doc"));
回答by Anon.
You want the File.createTempFile(String, String, File)overload.
你想要File.createTempFile(String, String, File)超载。
Which you would have seen immediately had you bothered to look at the documentation.
如果您费心查看文档,您会立即看到。

