winform 读取TXT文件 放在Label中

时间:2014-07-31 13:34:36   收藏:0   阅读:208
<span style="font-family: Arial, Helvetica, sans-serif;">#region 读取TXT 文件,放到Label中</span>
        private void ReadTXT(Label lab) {
            string strTxtAll = "";//定义一个string变量
            string abc = "C:\Users\xxb\Desktop\1.txt";//路径
            FileStream fs = new FileStream(abc, FileMode.Open, FileAccess.Read, FileShare.None);
            StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("GB2312"));
            string line = sr.ReadLine();
            strTxtAll = line + "\r\n";
            for (int ac = 0; line != null; ac++) {
                line = sr.ReadLine();
                strTxtAll += line + "\r\n";
            }
            lab.Text = strTxtAll;
            sr.Close();
            fs.Close();
        }
        #endregion
调用即可:
  ReadTxt(label1);



winform 读取TXT文件 放在Label中,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!