string line
string strShow = ""
while ((line = sr.ReadLine()) != null)
{
strShow = strShow + line + "\n"
}
rtxtRead.Text = strShow
sr.Close()
private void btnSaveToTxt_Click(object sender, EventArgs e){
// 假设你的程序根目录有一个MyData.txt的文件(在Debug文件夹下)
string path=Application.StartupPath+".\\MyData.txt"
if (File.Exists(path))
{
// 以追加的方式创建文件流对象sw
using (StreamWriter sw = new StreamWriter(path,true))
{
sw.WriteLine(textBox1.Text) // 把文本框的数据写入指定的文件
}
MessageBox.Show("一键保存成功。")
}
else {
MessageBox.Show("不存在MyData.txt的文件,请重新创建它。")
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)