Java file deletion error
The first reason is that there path
might be a directory
From the javadoc File#delete()
:
If this pathname denotes a directory, then the directory must be empty in order to be deleted.
Make sure the path is not an empty directory:
if (l_file.isDirectory()) {
String[] files = l_file.list();
if (files.length > 0) {
System.out.println("The " + l_file.getPath() + " is not empty!");
}
}
Another reason you can't uninstall path
is because you don't have permissions
Check your permissions:
if (l_file.canWrite())
l_file.delete();
source to share
Perhaps you can try to check if this is a file (not a directory) of its permissions using the methods File
:
boolean isFile() // if it is a directory it must be empty
boolean canWrite()
boolean canRead()
boolean canExecute()
Also, as you can read in the Java API: "On some operating systems, it may not be possible to delete the file while it is open and in use by this Java virtual machine or other programs."
If you are on Linux, you can try lsof <file_name>
to find out which process opened this file.
source to share