[英]StreamWriter generate IOException Unable to find the specified file
I have the following code: 我有以下代码:
using (StreamWriter writer = new StreamWriter(filename, true))
{
writer.WriteLine(mydata);
}
that from time to time generate this error: IOException.Message = "Unable to find the specified file"
. 有时会生成此错误:
IOException.Message = "Unable to find the specified file"
。
The filename string is specified by the user and can be a network location like: 文件名字符串由用户指定,可以是网络位置,例如:
\\mycorp\Shared\Data.xml
And mydata
variable is a string too. 而且
mydata
变量也是一个字符串。
Is it possible that this code will generate a FileNotFoundException
? 此代码是否有可能生成
FileNotFoundException
?
The answer to the question "Is it possible that this code will generate a FileNotFoundException
?" 问题“此代码是否有可能生成
FileNotFoundException
?”的答案。 is: No. 没有。
Source: https://msdn.microsoft.com/en-us/library/36b035cb.aspx 来源: https : //msdn.microsoft.com/en-us/library/36b035cb.aspx
I suggest checking where the exception is coming from. 我建议检查异常来自何处。 It should give a line number in the exception stack trace.
它应该在异常堆栈跟踪中给出一个行号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.