问题描述
我正在从msdn中读取 File.AppendAllText
方法
I was reading File.AppendAllText
method from msdn
http://msdn.microsoft.com/en-us/library/ms143356.aspx
我看到他们已将 FileNotFoundException
列出到该方法的可能例外列表中,但根据同一页面上有关该方法的描述
I saw they have listed FileNotFoundException
to possible exceptions list for the method but according to there description about method on the same page
这部分
似乎永远无法为该方法抛出该异常.
it seems this exception can never be thrown for this method.
推荐答案
如果您查看(说)Mono的实现(与Microsoft兼容),所有 File.AppendAllText
最终都会做(不考虑参数检查)是使用路径创建 StreamWriter
,然后对该对象调用 Write
.
If you take a look at (say) Mono's implementation (which is compatible with Microsoft's), all File.AppendAllText
ends up doing (argument checks aside) is creating a StreamWriter
with your path and calling a Write
on that object.
据我所知,在任何地方都没有列出使用过的构造函数或方法来引发 FileNotFoundException
,因此可能可能是文档错误.
Neither the used constructor nor the method are listed anywhere to throw a FileNotFoundException
, as far as I can tell, so it might be a documentation error.
这篇关于File.AppendAllText中的FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!