streamreader读出来的文件的饿内容为空

蓝色水 2007-09-29 10:33:00
StreamReader din = File.OpenText("b.txt");

string strall=null;
string str=null;
while((str = din.ReadLine()) != null)
{
strall = str + ",";

}

userAccount = strall;
...全文
161 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
蓝色水 2007-09-29
  • 打赏
  • 举报
回复
liurenfu 感谢,的确是字符集的问题,加了System.Text.Encoding.Default就解决了,thx
volezbin 2007-09-29
  • 打赏
  • 举报
回复
同级目录同楼上 StreamReader din = File.OpenText(@"d:\b.txt");
或者在config里面加上路径
jiatong1981 2007-09-29
  • 打赏
  • 举报
回复



#region Test
StreamReader din = File.OpenText(@"d:\b.txt"); //估计你的问题在这里,看看你的b.txt的文件路径怎么写的
string userAccount;
string strall = null;
string str = null;
while ((str = din.ReadLine()) != null)
{
strall += str + ",";

}
userAccount = strall;
#endregion


liurenfu 2007-09-29
  • 打赏
  • 举报
回复
StreamReader MyReader=new StreamReader("b.txt",System.Text.Encoding.Default);
this.textBox1.Text=MyReader.ReadToEnd();
jiatong1981 2007-09-29
  • 打赏
  • 举报
回复
把你的代码贴出来


StreamReader din = File.OpenText(@"d:\b.txt"); //估计你的问题在这里,看看你的b.txt的文件路径怎么写的
string userAccount;
string strall = null;
string str = null;
while ((str = din.ReadLine()) != null)
{
strall += str + ",";

}
userAccount = strall;


蓝色水 2007-09-29
  • 打赏
  • 举报
回复
还是读不出来,刚刚还读的出来,请达人相助
wuhq030710914 2007-09-29
  • 打赏
  • 举报
回复
string strall=null,设置成静态看看
hooo 2007-09-29
  • 打赏
  • 举报
回复
while((str = din.ReadLine()) != null)
{
strall = strall + str + ","; //改这句增加一个strall 不然就只会显示最后一行

}
jiatong1981 2007-09-29
  • 打赏
  • 举报
回复
StreamReader din = File.OpenText(@"d:\b.txt");
string userAccount;
string strall = null;
string str = null;
while ((str = din.ReadLine()) != null)
{
strall += str + ",";

}

userAccount = strall;

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧