Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with file system synchronization after moving a file using renameto  RSS feed

Sunny X Narula
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!