0

If I call File.delete() are the effects on the underlying file system immediately visible? Can I write to the same file name in the same process/thread after without worrying about bad things happening? If not, is there a way to sync the underlying file system with just a File object?

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
Steve M
  • 9,296
  • 11
  • 49
  • 98

1 Answers1

0

File.delete() return a boolean telling you if the file has been correctly deleted.
So you could write something like :

if(yourFile.delete()) {
  //keep doing what you want. You are now sure file has been deleted !
}

Also, before writing a new file, you could check if a file with the same name already exists.

From Oracle documentation :

Returns:
true if and only if the file or directory is successfully deleted; false otherwise  

Oracle source

Also there is a SO thread that might help you

Community
  • 1
  • 1
HelloSadness
  • 945
  • 7
  • 17
  • I'm not sure if the boolean means that the file is no longer visible in the file system or if it may be actually be deleted at a later time? – Steve M Nov 20 '16 at 21:18