在Java中:在目录中创建唯一的随机文件名 [英] In Java: create unique random filename in a directory
本文介绍了在Java中:在目录中创建唯一的随机文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在(我选择的)目录中创建随机的唯一文件名?
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
推荐答案
File.createTempFile()
允许您指定一个目录如下:
File.createTempFile()
allows you to specify a directory so:
File uniqueFile = File.createTempFile("post", ".html", new File("/var/www/doc"));
这篇关于在Java中:在目录中创建唯一的随机文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文