folder deletion

I have a problem deleting a folder....everything seems to be right,,but it doesnt work consistently,,,yeah the same code does delete the folder at times.

im attaching the code below:

[i]String path= outFilePath.substring(0,outFilePath.lastIndexOf("."));

File file=new File(path);

recursiveRemove(file);

public static void recursiveRemove(File file) {

try

{

if(file.isDirectory()) {

File[] contents = file.listFiles();

for(File temp : contents) {

recursiveRemove(temp);

}

}

System.out.println("Removed "+file+"? "+file.delete());

}

catch(Exception e)

{

System.out.println("the output error is below++++++++++++++++++++++++++++++++");

e.printStackTrace();

}

}

the first line is the place where it gives an error,but guess that code is correct as it gives the correct string when printed.

**in the first line,outputfilepath is the path to the zip file, and a folder in the same path exists with the same name,,so cutting of the ".zip " part

If ne more info is required,plz leme know...

Any help will be life saving

thnxxxx

[1196 byte] By [sun_java_helpa] at [2007-11-27 7:37:55]
# 1
You can't delete folders that have files inside or are otherwise locked by a process, like a shell being open with them as current working directory.
CeciNEstPasUnProgrammeura at 2007-7-12 19:18:33 > top of Java-index,Java Essentials,Java Programming...
# 2
but if u c my code ,,im deleting the files recursively first,only then deleting the folder,,,so i guess the folder becomes empty while deleting it.n i guess dats not a problem
sun_java_helpa at 2007-7-12 19:18:33 > top of Java-index,Java Essentials,Java Programming...