C#读取文件,为什么会少读最后一行? string s;while((s = streamReader.ReadLine()) != null){.............;} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string s;do{.............;}while((s = streamReader.ReadLine()) != null) while(this.dataReader.Read()){} while(streamReader.Peek!=-1 ){} streamReader.ReadLine输入流中的下一行;如果到达了输入流的末尾,则为空引用(Visual Basic 中为 Nothing)。你读到最后一行的时候,条件为空,就已经跳出了当然读不出来最后一样了…… 楼主的代码没有问题的楼主要给出全部的代码,估计是楼主的while循环体的问题,楼主是不是在里面用了streamReader.ReadLine 楼主的代码也许有个小问题:我也读过文件,一般是先读一行的楼主可以尝试用一下以下的代码:string s;s = streamReader.ReadLine();while(s!= null){ s = streamReader.ReadLine();.............;} while里面的代码拿来看看,估计是里面的代码有问题 一路向北是正解string s;do{.............;}while((s = streamReader.ReadLine()) != null) public static string GetConnStr() //求连接数据库连接字符串 { string source = ""; FileStream fs = new FileStream(Application.StartupPath + "\\ConnConfig.ini", FileMode.Open, FileAccess.Read, FileShare.None); StreamReader sr = new StreamReader(fs); while (!sr.EndOfStream) //直到文件结束 { source += sr.ReadLine(); source += ";"; } fs.Close(); sr.Close(); return source; }不知能不能帮助你? string str_ofread; str_ofread = sr_read_stru.ReadLine(); while (str_ofread!=null ) { this.listBox_stru.Items.Add(str_ofread); str_ofread = sr_read_stru.ReadLine(); }try this!!! 求助,ICSharpCode.SharpZipLib.Zip 如何进行分段压缩. [GridControl] 在gridcontrol列表中添加数据 C# cgdataadapter怎么引用 winform控件透明 关于滚动条 C#如何做Windows系统服务使程序自动运行??? C#操作word插入图片的问题 !!! 象windows XP中,那种弹出气泡窗口是如何来做的? 如何用C#连接oracle数据库? 对象的实例化异常。 c# 如何对图片进行编辑 C#如何关于sql分布式的问题
do
{
.............;
}while((s = streamReader.ReadLine()) != null)
while(this.dataReader.Read())
{}
{}
输入流中的下一行;如果到达了输入流的末尾,则为空引用(Visual Basic 中为 Nothing)。你读到最后一行的时候,条件为空,就已经跳出了
当然读不出来最后一样了……
楼主要给出全部的代码,估计是楼主的while循环体的问题,楼主是不是在里面用了streamReader.ReadLine
楼主可以尝试用一下以下的代码:
string s;
s = streamReader.ReadLine();
while(s!= null)
{
s = streamReader.ReadLine();
.............;
}
string s;
do
{
.............;
}while((s = streamReader.ReadLine()) != null)
{
string source = "";
FileStream fs = new FileStream(Application.StartupPath + "\\ConnConfig.ini", FileMode.Open, FileAccess.Read, FileShare.None);
StreamReader sr = new StreamReader(fs);
while (!sr.EndOfStream) //直到文件结束
{
source += sr.ReadLine();
source += ";";
}
fs.Close();
sr.Close();
return source;
}
不知能不能帮助你?
str_ofread = sr_read_stru.ReadLine();
while (str_ofread!=null )
{
this.listBox_stru.Items.Add(str_ofread);
str_ofread = sr_read_stru.ReadLine();
}try this!!!