怎么在用textbox向c#的txt文件里面写数据

2024-11-27 01:30:34
推荐回答(2个)
回答1:

string path=@"E:\我的文本.txt";
string text=this.textBox1.text.Trim(); //接收

FileStream fs=null;
try
{
fs=new FileStream(path,FileMode.Create,FileAccess.Write);
StreamWrite sw=new StreamWrite(fs,Encoding.UTF8);
sw.Write(text);
sw.Close();
}
catch
{
}
finally
{
fs.Close();
}

回答2:

文件读写啊,streamWrite对象