码迷,mamicode.com
首页 > Windows程序 > 详细

c# 打开文件和读取文件内容

时间:2018-01-11 11:27:49      阅读:305      评论:0      收藏:0      [点我收藏+]

标签:def   files   txt   gre   color   object   led   click   ade   

        private void button_Click(object sender, EventArgs e)
        {
                string fileName =string.Empty; //文件名
                //打开文件
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.DefaultExt = "txt";
                dlg.Filter = "Txt Files|*.txt";
                if (dlg.ShowDialog() == DialogResult.OK)
                    fileName = dlg.FileName;
                if (fileName == null)
                    return;
                 //读取文件内容
                 StreamReader sr = new StreamReader(fileName, System.Text.Encoding.Default);
                String ls_input = sr.ReadToEnd().TrimStart();
                if (!string.IsNullOrEmpty(ls_input))
                    isopen = true;
                sr.Close();
        }

 

c# 打开文件和读取文件内容

标签:def   files   txt   gre   color   object   led   click   ade   

原文地址:https://www.cnblogs.com/cxyzhangjie/p/8266777.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!