Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Delete directory - IOException: Unable to delete directory

Tags:

java

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 ?

like image 387
Alexandre Avatar asked May 25 '18 15:05

Alexandre


People also ask

How do I delete a full directory in Java?

Method 1: using delete() to delete files and empty folders Provide the path of a directory. Call user-defined method deleteDirectory() to delete all the files and subfolders.

How do I delete a non empty directory in Java?

In Java, to delete a non-empty directory, we must first delete all the files present in the directory. Then, we can delete the directory. In the above example, we have used the for-each loop to delete all the files present in the directory.

Can you delete a directory with files in Java?

Java isn't able to delete folders with data in it. You have to delete all files before deleting the folder.

Which method is used to delete a directory in Java?

By using the File.delete() Method The delete() method of the File class is used for deleting a directory.


1 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.

like image 110
Abhijit Pritam Dutta Avatar answered Oct 21 '22 22:10

Abhijit Pritam Dutta