First off, if what you want to do is move a file to a different directory, without leaving behind a copy in the orignal directory, then it is probably much quicker (both to code and to execute) if you use the File renameTo() method. If for some reason this doesn't work for you, then this is a tricky problem. The delete() method can be very frustrating in that it provides absolutely
no feedback about
why it fails; it simply returns false. (And often people don't remember to check this, but that's their fault.) Anyway, my guess is that during the copy process, you opened a FileInputStream or FileReader for the input file, and this is still open. The delete() method seems to fail when the file to delete is still open. To fix this, you need to make sure that the close() method is called when you are done with the file, before you attempt to delete. Don't let garbage collection take care of it - it will happen eventually, true, but you need the file closed
now for the delete to work. I always try to put the close() in a finally clause so that it will happen even if an error is thrown:
Or:
Do this religiously with all your streams, and hopefully you will not see this sort of mysterious error again.