c# - 为什么 File.Open 在覆盖现有文件方面比 File.Create 好得多?

标签 c# file

这与其他 SO question 有关询问如何覆盖现有文件。

最佳答案是这样的:

FileStream file = File.Open("text.txt", FileMode.Create);

我的回答是这样的:

FileStream fs = System.IO.File.Create(fileName);

在我写这个问题时,比分是 14-0,支持 Open

如果投票表示解决方案的优劣,这让我有点疑惑:

Is there something I'm missing in these methods that would make it clearly that much better to choose Open over Create?

最佳答案

对我来说,我确切地知道 File.Open("...", FileMode.Create) 做了什么,因为我可以将鼠标悬停在 FileMode.Create 上,它告诉我每次都会创建一个新文件。 File.Create("...") 没有指示它将执行此操作的工具提示。

关于c# - 为什么 File.Open 在覆盖现有文件方面比 File.Create 好得多?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/793753/

相关文章:

c# - 初始化语法与无参数构造函数语法

c# - 如果仅更改内部版本号或修订版号,则定位 GAC 程序集

java - 将 Java 代码生成的文件保存到用户定义的位置,例如下载功能

c# - 找不到模型

c# - 如何打开第二个表单?

scripting - 获取两个文件之间的相对路径的最佳/最简单/最快的方法?

python - 按列读取 CSV 文件

JavaScript Canvas 下载

c# - C#中的算术运算

file - 批处理文件删除文本文件的前 3 行