在VS2019上从文本文件读取时遇到一个奇怪的问题。我知道哪里出了问题,但我无法修复。
path1用于存储已构建的文本文件的绝对路径。仅此变量存储路径。
richtextbox用于显示从文本文件读取的内容。在使用前将其清洗。
String path1=this.textBox1.Text;
this.richTextBox1.Clear();
第五行是问题。
当我调试代码时,sr.ReadtoEnd()的值显示“此表达式可能会导致副作用,因此将不被评估”。
try
{
FileStream fs = new FileStream(path1,FileMode.Open);
StreamReader sr = new StreamReader(fs,Encoding.Default);
this.richTextBox1.Text = sr.ReadToEnd();//What's wrong????
sr.Close();
fs.Close();
MessageBox.Show("Read....");
}
catch (IOException ex)
{
MessageBox.Show("Failed to read...");
}
感谢您的帮助!
谢谢!