string path = Server.MapPath("~/Files/");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string fileFullPath = path + "test.txt";
StringBuilder str = new StringBuilder();
str.Append("neirong");
StreamWriter sw;
if (!File.Exists(fileFullPath))
{
sw = File.CreateText(fileFullPath);
}
else
{
sw = File.AppendText(fileFullPath);
}
sw.WriteLine(str.ToString());
sw.Close();
转载于:https://www.cnblogs.com/shiyige-216/p/7597705.html