The javadoc for File.delete()
public boolean delete()
Deletes the file or directory denoted by this abstract pathname. If this pathname >denotes a directory, then the directory must be empty in order to be deleted.
So a folder has to be empty or deleting it will fail. Your code currently fills the folder list with the top most folder first, followed by its sub folders. Since you iterrate through the list in the same way it will try to delete the top most folder before deleting its subfolders, this will fail.
Changing these line
for(String filePath : folderList) {
File tempFile = new File(filePath);
tempFile.delete();
}
to this
for(int i = folderList.size()-1;i>=0;i--) {
File tempFile = new File(folderList.get(i));
tempFile.delete();
}
should cause your code to delete the sub folders first.
The delete operation also returns false when it fails, so you can check this value to do some error handling if necessary.