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...
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 ?
3 Answers
You need to check the following to fix this issue:-
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/Job000000000676Add the account into the proper group. To do that first check with
ls -ltrexecute it inside/opt/appdata/conv/data/outand add your account to the group which has full permission to delete directories insideoutdirectoryAlso check if
Job000000000676has sub directory inside it. In such a condition you can execute unix command likerm -rf /opt/appdata/conv/data/out/Job000000000676. See how to execute unix command from java application for detail.
Hope this will help you.
There are files in your folder ? If yes, you should delete them before delete the folder
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