Proper way of waiting until a file is created

前端 未结 2 665
日久生厌
日久生厌 2021-01-21 18:51

I have the following code:

// get location where application data director is located
var appData = Environment.GetFolderPath(Environment.SpecialFolder.Applicati         


        
2条回答
  •  长情又很酷
    2021-01-21 19:17

    There is no need to create the file if you intend to use File.AppendAllText

    About the root cause for the error, and a preferred way to write to files in general:

    The file was created, and returned a stream that you didn't use/close. best method should be to use this stream to write to the file.

    using (FileStream fs = File.Create(file))
    {
         fs.Write("What ever you need to write..");
    }
    

提交回复
热议问题