What is the best way to generate a unique and short file name in Java

后端 未结 16 2358
不思量自难忘°
不思量自难忘° 2020-11-29 20:51

I don\'t necessarily want to use UUIDs since they are fairly long.

The file just needs to be unique within its directory.

One thought which comes to mind is

16条回答
  •  隐瞒了意图╮
    2020-11-29 21:25

    I understand that I am too late to reply on this question. But I think I should put this as it seems something different from other solution.

    We can concatenate threadname and current timeStamp as file name. But with this there is one issue like some thread name contains special character like "\" which can create problem in creating file name. So we can remove special charater from thread name and then concatenate thread name and time stamp

    fileName = threadName(after removing special charater) + currentTimeStamp
    

提交回复
热议问题