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?
Asked
Active
Viewed 40 times
0
Andrii Omelchenko
- 12,735
- 12
- 44
- 73
Steve M
- 8,843
- 10
- 44
- 89
1 Answers
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
Community
- 1
- 1
HelloSadness
- 895
- 7
- 16
-
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