Problem with file system synchronization after moving a file using renameto
Sunny X Narula
posted 7 years ago
As a part of a program I create a file and then rename it to a folder address where it is supposed to be kept.
I use the renameTo method to do this.
The method returns true indicating it was moved correctly.
I have tried doing
File f = new File(movedFile.getAbsolutePath());
and the f.exists returns true.
but say the parent folder of the moved file is homeFolder (=movedFile.getParentFile())
Now we use homeFolder.listFiles(Filter) to list the files
But this method responds in a irregular way.
Sometimes it gives the file in the result and sometimes it doesn't.
But when I add a 1 second delay in between it consistently finds the file.
I think this is some sort of write delay.
The adding a 1 second delay is not the ideal solution I was hoping for.
Can someone suggest a better way of doing this.