What is the best way to generate a unique and short file name in Java -
I do not necessarily want to use the UUID as they are too long.
An idea that comes to mind is to use File.createTempFile (string prefix, string suffix) , but this is incorrect because the file is not Is temporary
The matter of two files created in the same milliseconds should be handled.
OK, you can use 3-logic version: which will make you want it where you Unless you want to tell it, Java will not treat it differently from any other file. The only drawback is that the file name is guaranteed to be at least 8 characters long (for at least 3 letter suffixes, plus 5 or more characters generated)
If it is too long for you, I think you can always start with the filename "a", and then loop through "b", "c", etc. You can start unless you already exist.
Comments
Post a Comment