File deletion behaviour in Java

I'm using windows XP, Why does it takes a while for the JVM to delete a file, even though the File.Delete() method returns true? Is there a way to really know wheter a file was deleted?Thanks in advance
[224 byte] By [x-tremeDeva] at [2007-10-2 0:54:30]
# 1

What do you mean "takes a while"? If you're watching the directroy via Windows Explorer then you will need to wait for the refresh time of Explorer - it is not real time.

Need Java help? Want to help people who do? Sit down with a cup of Java at the [url=http://forums.hotjoe.com/forums/list.page]hotjoe[/url] forums.

Sure they're new - come get them started!

stdunbara at 2007-7-15 18:14:21 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

In a loop i use the File.fileList() method to detect if there are files in a directory. The loop is running continuosly, when i go trouhg and read the files listed in the array generated by the fileList method i deleted the files once they've been processed. When there are few files (lets say 1 or 2) in the directory, sometimes, even though the delete() method returns true, the fileList method returns the same one or two files again. These can happens maybe 3-4 times, i mean, the fileList in the loop "sees" the files for a while.

That's what i mean with "it takes a while"

x-tremeDeva at 2007-7-15 18:14:21 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

It really sounds like there is a bit of caching going on. I Googled on [url=http://www.google.com/search?hl=en&lr=&c2coff=1&q=file+system+caching+windows]some terms[/url] and learned alot. Basically it looks like Windows maintains a cache of disk blocks in memory. I'm honestly not sure that that is the issue you're seeing but it would make sense.

The proof would be to write a native code method that calls the Windows API to do about the same thing you're doing - a non-trival task without the right tools.

stdunbara at 2007-7-15 18:14:21 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4
Slow down your loop using a sleep statement - say about 10 ms - and see if that changes anything.
ChuckBinga at 2007-7-15 18:14:21 > top of Java-index,Java HotSpot Virtual Machine,Specifications...