public string GetLogByDate(string fileName)
{
//根据文件名,判断文件是否存在
string filePath =System.Web.HttpContext.Current.Server.MapPath("~/App_Log/")+ fileName + "-api.log";
string text = "";
//按行读取为字符串数组
string[] lines = System.IO.File.ReadAllLines(@filePath,Encoding.Default);
int i = 1;
int Num = 0;
foreach (string line in lines)
{
if (i == 1 && Num==0)
{
text += "<h4>第1条</h4>";
}
if (line != "")
{
text += "<li>" + line + "</li>";
Num = 1;
}
else
{
i++;
text += "<h4>第" + i + "条</h4>";
}
}
return text;
}
读取带有中文的txt文件
最新推荐文章于 2023-01-07 11:18:35 发布