在ASP.NET(C#)中的label的显示内容想要调用txt文件中的,请问代码要怎么写才好?万分感谢!

2024-12-13 12:47:16
推荐回答(2个)
回答1:

FileStream fs = new FileStream("文件位置", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
string str = sr.ReadToEnd();
label1.Text = str;

回答2:

using (FileStream fsRead = new FileStream("txt文件地址", FileMode.Open))
{
int fsLen = (int)fsRead.Length;
byte[] heByte = new byte[fsLen];
int r = fsRead.Read(heByte, 0, heByte.Length);
string myStr = System.Text.Encoding.UTF8.GetString(heByte);
lable.text=myStr ;
}