这与其他 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
overCreate
?
最佳答案
对我来说,我确切地知道 File.Open("...", FileMode.Create)
做了什么,因为我可以将鼠标悬停在 FileMode.Create
上,它告诉我每次都会创建一个新文件。 File.Create("...")
没有指示它将执行此操作的工具提示。
关于c# - 为什么 File.Open 在覆盖现有文件方面比 File.Create 好得多?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/793753/