Windows API 的 CreateFile() 中 OPEN_ALWAYS 和 CREATE_ALWAYS 的区别 [英] Difference between OPEN_ALWAYS and CREATE_ALWAYS in CreateFile() of Windows API
本文介绍了Windows API 的 CreateFile() 中 OPEN_ALWAYS 和 CREATE_ALWAYS 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能解释一下CreateFile() windows API的函数?
Can anyone explain what the difference is between the creation dispositions OPEN_ALWAYS
and CREATE_ALWAYS
of the CreateFile() function of the windows API?
对我来说,他们似乎都只是如果文件不存在则创建文件".
To me it seems that they both simply 'create the file if it does not already exist'.
推荐答案
CREATE_ALWAYS
如果文件已经存在,也会截断内容.另一方面,OPEN_ALWAYS
不会破坏已经存在的文件.
CREATE_ALWAYS
also truncates the contents if the file already exists. On the other hand, OPEN_ALWAYS
will not clobber an already existing file.
以下是表格形式的不同值的工作原理:
Here's how the different values work in tabular form:
| When the file...
This argument: | Exists Does not exist
-------------------------+------------------------------------------------------
CREATE_ALWAYS | Truncates Creates
CREATE_NEW +-----------+ Fails Creates
OPEN_ALWAYS ===| does this |===> Opens Creates
OPEN_EXISTING +-----------+ Opens Fails
TRUNCATE_EXISTING | Truncates Fails
这篇关于Windows API 的 CreateFile() 中 OPEN_ALWAYS 和 CREATE_ALWAYS 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文