//C#写TXT文档 String strDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); string filePath = strDir + "\\putin.txt"; FileStream fs = new FileStream(filePath, FileMode.Append); StreamWriter sw = new StreamWriter(fs); //开始写入 sw.Write(sUsr + "\r\n"); sw.Write(sPwd + "\r\n"); //清空缓冲区 sw.Flush(); //关闭流 sw.Close(); fs.Close()