I'm trying to delete some files on a windows machine using apache commons-io's FileUtils.deleteDirectory method (The version of the commons library is 2.4). Said method eventually calls the "forceDelete" FileUtils method which calls "file.delete()" on line 2273 here:
2268 public static void forceDelete(File file) throws IOException {
2269 if (file.isDirectory()) {
2270 deleteDirectory(file);
2271 } else {
2272 boolean filePresent = file.exists();
2273 if (!file.delete()) {
2274 if (!filePresent){
2275 throw new FileNotFoundException("File does not exist: " + file);
2276 }
2277 String message =
2278 "Unable to delete file: " + file;
2279 throw new IOException(message);
2280 }
2281 }
2282 }
Now, file.delete, calls FileSystem.delete(this) for the file in question and this is the part where I'm not exactly sure what happens. FileSystem.delete is supposed to return true if the file is deleted and false if there was some sort of issue and the file was not deleted. When trying to delete the file the method returns "true" but the file remains in the directory and because of the directory not being emptied properly it cannot be deleted later in the FileUtils.deleteDirectory method throwing an exception.
The file can be deleted manually, from the windows file explorer at any time until the fileSystem.delete(this) method is called. Once that method is called the file cannot be deleted by the file explorer and disappears when the application is closed.
The reason I mentioned windows several times is because this issue does not occur on linux machines.
Which finally leads me to my question, "Does anyone know what might be the cause of this issue or at least give some insight in how to get some answers?"
This is my first post so I'm sorry if I did something wrong, thanks in advance.