我需要在Java中创建一些唯一的文件,计划使用UUID.randomUUID来生成它们的名称。会不会出现冲突?我是否应该像下面这样做,或者我不用担心这个问题?
Integer attemptsToGenerateUUID = 1;
while (true) {
UUID fileUUID = UUID.randomUUID();
if (fileDoesNotExistwith this UUID name) {
save file;
break;
}
attemptsToGenerateUUID += 1;
if (attemptsToGenerateUUID > 64) {
return false;
}
}