//由于日志中含有中文,用常用的LoadFile方法会含有乱码,所以用这种流的方式,一行一行的读。
string fullPath = @"F:\comback\Release\log\20121218.Log";
StringBuilder sb = new StringBuilder("");
StreamReader streamReader = null;
try
{
streamReader = new StreamReader(fullPath, Encoding.UTF8);
string line = streamReader.ReadLine();
while (!string.IsNullOrEmpty(line))
{
sb.Append(line + "\n");
line = streamReader.ReadLine();
}
this.richTextBox1.Text = sb.ToString();
}
catch (Exception ee)
{
MessageBox.Show("" + ee.Message);
}
finally
{
if (streamReader != null)
{
streamReader.Close();
}
}c# 将日志文件显示在RichTextBox控件里
使用流方式逐行读取中文日志文件
最新推荐文章于 2025-10-24 12:41:52 发布
本文详细介绍了如何使用流方式逐行读取包含中文的日志文件,避免了乱码问题,并展示了将读取内容显示到文本框的操作。
678

被折叠的 条评论
为什么被折叠?



