V
vandmzah
Hi,
In my code, I have a method which looks pretty much like this:
protected void clear() {
File[] leftDirs = tempDir.listFiles();
for (int i = 0; i < leftDirs.length; i++) {
boolean deleted=leftDirs.delete();
if(!deleted)
System.out.println("Can't delete" + leftDirs);
}
leftDirs = tempDir.listFiles();
if(leftDirs.length>0)
System.out.println("Files not deleted!" );
}
To my surprise, I am getting inconsistently the message "Files not
deleted!" without getting the "Can't delete" + leftDirs message.
In my test case I am trying to delete a single directory. When I check
with a debugger, the directory is no longer there.
So it looks like delete(); method returns true, and the directory is
being deleted, but not immediately. My expectation was that if
..delete() returns true, it is guaranteed that the directory is removed.
Could please someone explain?
In my code, I have a method which looks pretty much like this:
protected void clear() {
File[] leftDirs = tempDir.listFiles();
for (int i = 0; i < leftDirs.length; i++) {
boolean deleted=leftDirs.delete();
if(!deleted)
System.out.println("Can't delete" + leftDirs);
}
leftDirs = tempDir.listFiles();
if(leftDirs.length>0)
System.out.println("Files not deleted!" );
}
To my surprise, I am getting inconsistently the message "Files not
deleted!" without getting the "Can't delete" + leftDirs message.
In my test case I am trying to delete a single directory. When I check
with a debugger, the directory is no longer there.
So it looks like delete(); method returns true, and the directory is
being deleted, but not immediately. My expectation was that if
..delete() returns true, it is guaranteed that the directory is removed.
Could please someone explain?