Java File.list() consistent order? -
this awful question (in mind) , i've tried best find myself useful documentation little luck - anyway, here goes:
i have code needs operation on files in directory. set directory in file object , use fileobject.list() iterate on files in directory. left code running overnight , (after chugging) crashed @ point. i'm trying figure out @ point happened (yes had awful logging). now, according this javadoc there no guarantee of order (alphabetical or otherwise) when listing files, i'm wondering if there guarantee of consistency? meaning when run same code twice, exact same order of files? logic tells me should , i've resumed operations based on i'm suspicious of this. also, i'm curious on 'no specific order means' javadoc.
that language means should not rely on property of order including consistency run run.
if there linked list of files in in-memory data structure, driver might move accessed front of list optimize repeated file access. might change order in files listed though no file has been modified.
if want consistent order, can like
arrays.sort( myfilearray, new comparator<file>() { public int compare(file a, file b) { return a.getname().compareto(b.getname()); } });
Comments
Post a Comment