您的位置:首页 > 编程语言 > C#

c# 将日志文件显示在RichTextBox控件里 分类: .NET 2012-12-18 15:54 722人阅读 评论(0) 收藏

2012-12-18 15:54 681 查看
//由于日志中含有中文,用常用的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();
}
}




                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐