private void button2_Click(object sender, EventArgs e)
{
string filePath = "";
OpenFileDialog opd = new OpenFileDialog();
if (opd.ShowDialog() == DialogResult.OK)
{
filePath = opd.FileName;
}
StreamReader sr = new StreamReader(filePath,Encoding.Default);
string s = sr.ReadLine();
while (sr.ReadLine()!=null)
{
textBox1.Text+=s + "\r\n";
s = sr.ReadLine();
}
}
创建一个10行的文本,为什么只能读出来奇数行?无法全部读出来,怎么解决?

c#读取文本,不能全部读出来?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- wlj1234 2020-07-01 10:26关注
while (sr.ReadLine()!=null) //这里又读了一行
改如下
string s = sr.ReadLine();
while (s!=null)
{
textBox1.Text+=s + "\r\n";
s = sr.ReadLine();
}本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报