<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);
版权声明:本文为博主原创文章,未经博主允许不得转载。