日期:2014-05-17  浏览次数:20870 次

初学关于readline 的问题
我想从一个文本文件中读取所有的数据,但是使用 readline 只能读取一个回车符以前的字符,请教各位介绍合适的方法。谢谢。
------最佳解决方案--------------------

//点击打开按钮的事件
        private void miOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog dig=new OpenFileDialog();
            dig.ShowDialog();
            if (dig.FileName!="")
            {
                SetTitle(dig.FileName);
                filename = dig.FileName;
                OpenFile(dig.FileName);//调用OpenFile方法
            }
            else
            {
                MessageBox.Show("请选择文件!");
            }
           
        }

        //打开文件的方法
        protected void OpenFile(string path)
      {
          try
          {
              textBox1.Clear();
              textBox1.Text = File.ReadAllText(path, UnicodeEncoding.GetEncoding("GB2312")); //文件的读取
          }
          catch(IOException e)
          {
              MessageBox.Show(e.Message, "hhh",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
          }
      }

------其他解决方案--------------------
http://msdn.microsoft.com/zh-cn/library/system.io.file.readalllines

File.ReadAllLines 方法
------其他解决方案--------------------

            string path = @"E:\CollegeStudy\c# 资料\C__WCF入门学习.txt";
            StreamReader sr = new StreamReader(path, Encoding.GetEncoding("GB2312"));
            string text = sr.ReadToEnd();
            Console.WriteLine(text);
            sr.Close();

------其他解决方案--------------------