zoukankan      html  css  js  c++  java
  • C#文件读取

    找了几个方法

      Stopwatch sw = new Stopwatch();
                sw.Reset();
                sw.Start();
                this.richTextBox1.Text = string.Empty;
                string line = string.Empty;
                StringBuilder sb = new StringBuilder();
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter = "txt文件|*.txt";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    StreamReader sr = new StreamReader(dlg.FileName, Encoding.GetEncoding("GB2312"));
                    int nchar;
                    nchar = sr.Read();
                    while (nchar != -1)
                    {
                        sb.Append(Convert.ToChar(nchar).ToString());
                        nchar = sr.Read();
    
                    }
                    sr.Close();
                    this.SetRichT(sb.ToString());
                    sw.Stop();
                    MessageBox.Show(sw.ElapsedMilliseconds.ToString());
    
                }

     测试文件174Mb

     耗时:

    方法2

     Stopwatch sw = new Stopwatch();
                sw.Reset();
                sw.Start();
                this.richTextBox1.Text = string.Empty;
                string line = string.Empty;
                StringBuilder sb = new StringBuilder();
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter = "txt文件|*.txt";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    StreamReader sr = new StreamReader(dlg.FileName, Encoding.GetEncoding("GB2312"));
                    while ((line = sr.ReadLine()) != null)
                    {
                        sb.Append(line);
    
                    }
                    this.SetRichT(sb.ToString()); sw.Stop();
                    MessageBox.Show(sw.ElapsedMilliseconds.ToString());
                }

    耗时:

    方法3

     Stopwatch sw = new Stopwatch();
                sw.Reset();
                sw.Start();
                this.richTextBox1.Text = string.Empty;
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter = "txt文件|*.txt";
                string line = string.Empty;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    StreamReader sr = new StreamReader(dlg.FileName, Encoding.GetEncoding("GB2312"));
                    line = sr.ReadToEnd();
                    this.SetRichT(line); sw.Stop();
                    MessageBox.Show(sw.ElapsedMilliseconds.ToString());
                }
     
    delegate void SetRitchText(object o);
            private void SetRichT(object o)
            {
                if (this.richTextBox1.InvokeRequired)
                {
                    this.richTextBox1.BeginInvoke(new SetRitchText(this.SetRichT), o);
                }
                else
                {
    
                    this.richTextBox1.Text += o + "
    ";
                    this.textBox1.Text = o.ToString().Length.ToString();
                }
            }
  • 相关阅读:
    jsp分页原理
    解决PowerDesigner 错误:Invalid repository user or password!
    JSP禁用缓存常用方法
    PowerDesigner 15破解补丁
    PowerDesigner建立与数据库的连接,以便生成数据库和从数据库生成到PD中。[Oracle 10G版]
    二十三、Intent
    axis2+spring集成
    ASP.NET获取MS SQL Server安装实例
    显示非站点目录图片
    行为的抽象即是接口(Interface)
  • 原文地址:https://www.cnblogs.com/bantongshui/p/3172644.html
Copyright © 2011-2022 走看看