When is it okay to check if a file exists?

前端 未结 18 2299
再見小時候
再見小時候 2020-11-28 06:52

File systems are volatile. This means that you can\'t trust the result of one operation to still be valid for the next one, even if it\'s the next line of code. You can\'t

18条回答
  •  一生所求
    2020-11-28 07:08

    This may be too simplistic, but I would think the primary reason for checking for the existence of a file (hence the existence of .Exists()) would be to prevent unintended overwrites of existing files, not to avoid exceptions caused by attempting to access non-existent nor non-accessible files.

    EDIT 2

    This was, in fact, too simplistic and I recommend you see Stephen Martin's response.

提交回复
热议问题