Exception when deleting directory using Fileutils.deleteDirectory

Asked

Viewed 426 times

2

The directory has 6 files inside it. The exception is java.io.Ioexception: Unable to delete file: tmp umDosArchives. Manually, I can delete all the files and the directory. I used the canWrite method, from File, to see if there was any lock, but it always returns true. File access permissions are also correct. What may be happening?

File tmpDir = new File("tmp");
if (tmpDir.exists()) {
    FileUtils.deleteDirectory(tmpDir);
}
  • Put the code you are using to do the deletion.

  • I posted the code. The exception occurs in Fileutils.deleteDirectory

  • 3

    The File.delete command, for directory, or in the case File.eleteDirectory, is unclear whether this is also true, http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html, will only work for empty directories. And always in java, pass the full path. Check this article, alias the articles on this site are very good: http://www.mkyong.com/java/how-to-delete-directory-in-java/

  • 1

    From what I understand, File.deleteDirectory should work because it says it deletes recursively. The article code worked and is very good. Thank you!

  • @user1902062 publish a response with the solution found.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.