的位置C#保存文件我想保存到這樣的文件:在您的應用程序
string path = AppDomain.CurrentDomain.BaseDirectory;
fs = new System.IO.FileStream(path, System.IO.FileMode.Append, System.IO.FileAccess.Write);
但雖然目錄中我得到DirectoryNotFoundException。
這裏是方法
public static void WriteToFile(string s)
{
string path = AppDomain.CurrentDomain.BaseDirectory;
fs = new System.IO.FileStream(path, System.IO.FileMode.Append, System.IO.FileAccess.Write);
sw = new System.IO.StreamWriter(fs);
sw.WriteLine(s);
sw.Flush();
sw.Close();
fs.Close();
}
我不知道爲什麼會這樣。由於
有非常好的機會,'path'指向目錄(大約100%)。你能否澄清爲什麼你期望文件創建成功的路徑到目錄? –