Java, IO - fastest way to remove file
FileUtils.cleanDirectory(new File("/usr/share/test")); //linux
FileUtils.cleanDirectory(new File("C:\\test")); //windows
I'd suggest checking the Apache Commons IO library. They have some pretty helpful methods for deleting files in the FileUtils class.
You may find it an order of magnitude faster if you shell out and have the system delete them. You'd have to be able to hit a stopping point (where no files were being processed) then shell out and delete "*" or . or whatever it is for your OS.
(Note, this makes your program VERY os dependent!)
Be sure on Windows and Mac that you are bypassing the trashcan feature!
The nice thing about del . or rm * is that they SHOULD batch the operation rather than repeatedly opening, modifying and closing the directory.
You might also write filenames with a pattern like a001, a002, a003, ... and when you reach a999 you go to b001 and delete a*.
Well, file.delete()
should suffice (it is internally implemented as a native method)