zoukankan      html  css  js  c++  java
  • c# 将日志文件显示在RichTextBox控件里 分类: .NET 20121218 15:54 722人阅读 评论(0) 收藏

    //由于日志中含有中文,用常用的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();
                    }
                }


    
    
    
        
            

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    HDU 5650 异或
    HDU 5646
    HDU 5645
    P2075 [NOIP2012T5]借教室 区间更新+二分查找
    HDU 5641
    读写分离
    linux执行cmd之一
    html2image
    挂载引起的权限问题
    如何防止sql注入
  • 原文地址:https://www.cnblogs.com/configman/p/4657572.html
Copyright © 2011-2022 走看看