简体   繁体   中英

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" .

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.

Is it possible that this code will generate a FileNotFoundException ?

The answer to the question "Is it possible that this code will generate a FileNotFoundException ?" is: No.

Source: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM