winform 读取TXT文件 放在Label中
2020-12-13 05:43
标签:winform 读取 txt winform 读取TXT文件 放在Label中,搜素材,soscw.com winform 读取TXT文件 放在Label中 标签:winform 读取 txt 原文地址:http://blog.csdn.net/u013816709/article/details/38312253#region 读取TXT 文件,放到Label中
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);
下一篇:Python Web编程