Failed to delete original file

user739115 picture user739115 · Apr 19, 2013 · Viewed 15.4k times · Source

we are running jar using batch file as window service and place xml files in c:/processed directory;

if xml has an errorneous format then move it to error folder; we are using below method to move the file to error folder but getting below exception.

I think when the process is running its not able to move the file to error folder .

FileUtils.moveToDirectory("a.xml", "c:/processed/error", false);

exception in movedErrorFolder: Failed to delete original file 'c:/processed/a.xml' after copy to 'c:/processed/error/a.xml'

Answer

mki picture mki · Apr 19, 2013
  1. The java process does not have the right to delete the file, but if you can write on it then you can delete it.
  2. The file is locked by another process. This occurs typically when you write a csv open with Excel.
  3. The file is locked by the java process self, close() the file before moving it.