The getName () call returns only the file name, not any directory information. Therefore, you can rename the file to another directory.
Try adding the contained directory to the file object you pass to rename
currentFile.renameTo(new File(currentDirectory, formattedName));
As well as others, you should check the return value of renameTo, which is probably false, or use the new methods in the Files class, which, as I discovered, generate quite informative IOExceptions.
Michael krussel
source share