File.AppendAllText中的FileNotFoundException [英] FileNotFoundException in File.AppendAllText

查看:43
本文介绍了File.AppendAllText中的FileNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从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

打开一个文件,将指定的字符串附加到该文件,然后关闭该文件.如果该文件不存在,则此方法将创建一个文件,将指定的字符串写入文件,然后关闭文件.

Opens a file, appends the specified string to the file, and then closes the file. If the file does not exist, this method creates a file, writes the specified string to the file, then closes the file.

这部分

如果文件不存在,则此方法将创建文件

If the file does not exist, this method creates a file

似乎永远无法为该方法抛出该异常.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆