Java - Delete Directory - Ioexception: Unable to Delete Directory

I'm trying to delete two repositories

org.apache.commons.io.FileUtils.deleteDirectory(jobInDirectory);
org.apache.commons.io.FileUtils.deleteDirectory(jobOutDirectory);

Path are right

Rights on directory too

The first is well deleted but not the second. Every file inside was deleted but not the directory

java.io.IOException: Unable to delete directory /opt/appdata/conv/data/out/Job000000000676.

I looked to see if another process had locked it using the command lsfo and no other process uses it...

Any idea ?

1

3 Answers

You need to check the following to fix this issue:-

  1. User Id/account with which you are running your application must have permission to delete the below directory. If you are running the java application with your account then you must have permission to delete the below directory.

     /opt/appdata/conv/data/out/Job000000000676
    
  2. Add the account into the proper group. To do that first check with ls -ltr execute it inside /opt/appdata/conv/data/out and add your account to the group which has full permission to delete directories inside out directory

  3. Also check if Job000000000676 has sub directory inside it. In such a condition you can execute unix command like rm -rf /opt/appdata/conv/data/out/Job000000000676. See how to execute unix command from java application for detail.

Hope this will help you.

1

There are files in your folder ? If yes, you should delete them before delete the folder

1

Did you check permissions on that directory/file to ensure the user executing the command has sufficient rights?

Alternatively, if another process has a handle on the file, that would also cause a problem. Assuming you're using a linux based OS, try using the command: fuser /opt/appdata/conv/data/out/Job000000000676

Good luck

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest