Files.walkFileTree does not enumerate files which are created while traversing (Win)

Alan Bateman Alan.Bateman at Sun.COM
Tue Aug 5 08:28:47 PDT 2008


Rajendra Gutupalli wrote:
> Hi Alan,
>
> I have tried to see whether Files.walkFileTree() lists the files which 
> are created while traversing a directory. In  preVisitDirectory() 
> method I have created a file to see whether visistFile() methods gets 
> a hit for the newly created file. In Solaris and Linux the visitFile() 
> method is called for the newly created file but in Windows it does not 
> get called. 
The walkFileTree utility method is an internal iterator that makes use 
of iterators obtained from directory streams. These iterators are 
specified (in DirectoryStream) to be "weakly consistent" and may not 
reflect updates to the directory after the directory is opened. So the 
different behavior you observe is allowed (and I'm impressed that you 
find these issues). Anyway, the reason for the difference is that the 
underlying implementation is very different. On Windows then information 
for the "first" file is returned when the directory is opened and the 
search handle obtained. This creates a difference for the case that the 
directory is initially empty; if you create the directory in a non-empty 
directory then you'll see it will be returned by the iterator.

-Alan.



More information about the nio-dev mailing list