When is it okay to check if a file exists?

前端 未结 18 2372
再見小時候
再見小時候 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:21

    One example: You may be able to check for existence of files which you are unable to open (due to, for example, permissions).

    Another, possibly better example: You want to check for the existence of a Unix device file. But definitely do not open it; opening it has side effects (e.g., open/close /dev/st0 will rewind the tape)

提交回复
热议问题