直接上代码,读取一个.txt文件
StringBuilder sbStr = new StringBuilder(10000000);
string str = string.Empty;
using (FileStream fi = new FileStream(Server.MapPath("~/待报废.txt"), FileMode.Open))
{
StreamReader sr = new StreamReader(fi);
str = sr.ReadLine();
while (!string.IsNullOrEmpty(str))
//while (!string.IsNullOrEmpty(str = sr.ReadLine()))
{
sbStr.Append(str).Append(",");
}
}
Response.Write(sbStr.ToString());
提示
如果屏蔽掉
str = sr.ReadLine();
while (!string.IsNullOrEmpty(str));
使用while (!string.IsNullOrEmpty(str = sr.ReadLine())) 又没有问题!