I have noticed a weird behavior when listing files in a directory. My situation is i have a list of txt files which i save in database and corresponding to those data files there are xml file that contains some tags for each txt which are associated as their meta-properties in db.
When i list files in from directory and read xml file some how the stream is changing and listing the file again which has already been added to db. Filenames are id in my db and are unique,re-listing them violates the primary key constraint.
i wanted to know why does the listing gets disturbed?
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(folderReader,filter){
for (Path file : directoryStream) {
// Read XML
// add txt file to database
// attach meta props to that file
}
}catch(IOException ex){}
Now for some file it runs fine but then some how the files that had already been listed are coming back again. Like 1.txt was processed and saved in db but in the loop later on it is listed again.