c# - 使用 C# 从文本文件中读取

标签 c#

所以我正在制作一个聊天程序,但我在文本框中创建一个新行而不是覆盖其他消息时遇到问题。这是我的代码:

        private void refreshRate_Tick(object sender, EventArgs e)
        {
        String ChatPath = @"Path";
        String line;
        try
        {
            StreamReader sr = new StreamReader(@"Path");
            line = sr.ReadLine();
            richTextBox1.Text = null;
            while (line != null)
            {
                richTextBox1.AppendText(Environment.NewLine);
                richTextBox1.Text = line;
                line = sr.ReadLine();
            }
            sr.Close();
        }
        catch (Exception r)
        {
            Console.WriteLine("Exception: " + r.Message);
        }
        finally
        {
        }
    }

最佳答案

您不需要StreamReaderEnvironment.NewLine

richTextBox1.Text=File.ReadAllText(path);

关于c# - 使用 C# 从文本文件中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19481333/

相关文章:

c# - UML 静态工厂

c# - 如何制定标准(C# 与 VB.NET)

c# - AudioGraph DesiredSamplesPerQuantum属性被忽略

c# - 如何在 MVC 3 Razor View Engine 中使用 C# 显示和隐藏 Div?

c# - 删除字符串特定部分的数字(括号内)

C# 将 uint[] 转换为 byte[]

c# - 清洁代码 : Should Objects have public properties?

c# - 使用 Dynamic 或 Reflection.emit

c# - Windows Phone 开发错误错误 "Csc.exe"退出,代码为 -1073741819

c# - 使用内部集合创建 where 谓词的动态查询