gpt4 book ai didi

c# - 在 C# 中打开文本文件

转载 作者:行者123 更新时间:2023-11-30 20:06:39 25 4
gpt4 key购买 nike

当我尝试打开一个 .txt 文件时,它只在我的 文本框 中显示它的位置。我没有主意:(希望你能帮助我...

代码:

private void OpenItem_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
System.IO.StringReader OpenFile = new System.IO.StringReader(openFileDialog1.FileName);
richTextBox1.Text = OpenFile.ReadToEnd();
OpenFile.Close();
}

最佳答案

A StringReader从您传递给它的字符串中读取字符——在本例中为文件名。如果要读取文件的内容,请使用 StreamReader :

var OpenFile = new System.IO.StreamReader(openFileDialog1.FileName);
richTextBox1.Text = OpenFile.ReadToEnd();

关于c# - 在 C# 中打开文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9559778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com