Tag: 文件写作

正确等待文件创建的方法

我有以下代码: // get location where application data director is located var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); // create dir if it doesnt exist var folder = System.IO.Path.Combine(appData, “SomeDir”); if (System.IO.Directory.Exists(folder) == false) System.IO.Directory.CreateDirectory(folder); // create file if it doesnt exist var file = System.IO.Path.Combine(folder, “test.txt”); if(System.IO.File.Exists(file)== false) System.IO.File.Create(file); // write something to the file System.IO.File.AppendAllText(file,”Foo”); 此代码在最后一行崩溃( An […]