Directory delete() ?

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top