猿问

StreamWriter生成IOException无法找到指定的文件

我有以下代码:


using (StreamWriter writer = new StreamWriter(filename, true))

{

   writer.WriteLine(mydata);

}

有时会产生此错误:IOException.Message = "Unable to find the specified file"。


文件名字符串由用户指定,并且可以是网络位置,例如:


\\mycorp\Shared\Data.xml

而且 mydata变量也是一个字符串。


此代码是否有可能生成一个FileNotFoundException?


蝴蝶不菲
浏览 206回答 1
1回答
随时随地看视频慕课网APP
我要回答