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

C# 如何在textbox里显示txt文件的内容
  //如何在textbox里显示txt文件的内容   
    private void getText()
    {
        string path = @"e:/confirm.txt";//读取文件txt   
        StringBuilder b = new StringBuilder();
        using (FileStream fs = new FileStream(path, FileMode.Open))
        {
            using (StreamReader sr = new StreamReader(fs))
            {
                while (!sr.EndOfStream)
                {
                    string sLine = sr.ReadLine();
                    if (sLine.Length < 1)
                    {
                        continue;
                    }
                    b.AppendLine(sLine);
                }
            }
        }

        TextBox1.Text = b.ToString();

    }

?