I need to rename a file.
Path destPath = Paths.get(directoryPath, hash);
Files.move(path, destPath);
The problem is that when I'm trying to "rename" the file, it can already exist.
Is there anyway to solve it by convention adding a suffix like -number
?
For example, if I need to rename to newfile
and newfile
and newfile1
exist, I want to rename to rename2
.
If at the time to rename newfile2
file, another file is renamed to newfile2
then newfile3
should be written...
Any ideas?