C#winform读取.txt文件

来源:互联网 发布:北师大网络远程教育 编辑:程序博客网 时间:2024/05/16 17:20

1.winform中有textBox来接受文件中的数据

2.我将下面代码写在了button按钮点击事件中

3.需要添加命名空间using   System.IO;和using System.Text;

            string str;

            StreamReader sr = new StreamReader("D:\\date.txt", false);
            str = sr.ReadLine().ToString();
            sr.Close();
            this.textBox2.Text = str;///读取