Take the 2-minute tour ×

Do the methods in Apache's FileUtils perform synchronous (blocking) i/o?

I am making a call to FileUtils.copyDirectoryToDirectory. In my next line, I want to delete the directory that I copied.


FileUtils.copyDirectoryToDirectory(source, destination);

Just want to make sure this is "safe" and asynchronous (non-blocking) i/o isn't happening.


share|improve this question

1 Answer 1

up vote 2 down vote accepted

Two things:

  1. FileUtils is not part of the standard JDK, it a class in the Apache Commons IO library.
  2. The operations you mentioned do not use non-blocking IO.

So to answer your question, yes, your overall operation is safe.

share|improve this answer
Thanks so much. The reason I asked is because we are sometimes getting this error after the second line is excecuted: java.io.IOException: Unable to delete directory <directory>. Not sure why yet. –  h-bomb Apr 11 '12 at 19:09
That should read: Unable to delete directory <source>. Not a very helpful message. We're thinking it may be due to file(s) inside the directory being locked. The files/directories are stored on a Mac OS X system. After we upgraded the OS from 10.4 to 10.6, our users occasionally get this error when they use our system to try and delete. At this point, we're not sure how to debug this, since we're not able to duplicate the issue on our local systems. –  h-bomb Apr 12 '12 at 16:14
You might try putting a slight delay between copying and deleting, in the case that file handles are still open at the OS level. Also, do you have a guarantee that the user will not have any files in the source directory opened in another program? –  Perception Apr 12 '12 at 16:17
No guarantees, no. We actually don't care if the files are open - the content is static (served up by Apache). If we could somehow force delete, that would be great, but there doesn't seem to be a way using FileUtils. –  h-bomb Apr 12 '12 at 16:20
You may want to try using FileUtils.forceDelete, it makes a more concerted effort to remove files and directories. It will also return you a useable error if it could not delete the directory for any reason. –  Perception Apr 12 '12 at 16:42

Your Answer


