There are different reasons why files cannot be deleted; for example (on Windows) when some process has the file open, or when the user doesn't have permission to delete the file. If these are files that you read or wrote in your own Java program, make sure that you close the file (or any input / output streams on the file) before you try to delete it.
And Your directory might contain other directories in which case you would have to go into those and delete the files there in as well, if at all empty according to you is no files/directories to be present.
I have Closed all the inputstreams but there is no positive change.
The situation is am Having text files which are getting converted to Pdf. The pdfs are getting sent to an e-mail adress contained in the text files. The program is then supposed to delete both the pdfs and the text files. All the pdfs are getting deleted and Some of the text files. The question is now that the program is reading from all the text files and sending all the Pdfs, Why isn't it deleting all the text files but choosing which ones to delete and leaving some? I do not have other Directories in the same Directory.