private void importTxtNoAdd()
{
string line;
string sFileName = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)//弹出文件选择器,选择文件
{
sFileName = openFileDialog1.FileName;//将文件名获取出来赋值给对应的变量
iXH = 0;
System.IO.StreamReader file = new System.IO.StreamReader(sFileName);
while ((line = file.ReadLine()) != null)
{
//这里的Line就是您要的的数据了
iXH++;//计数,总共几行
}
file.Close();//关闭文件读取流
}
}
StreamReader sr=new StreamReader ("TXT的路径。");while (true)
{
string str = sr.ReadLine();
if (String.IsNullOrEmpty(str))
{
break;
}
Console.WriteLine(str);
}
SteamReader sr = new StreamReader("...txt");while(sr.ReadLine()!=null){string str = sr.ReadLine();if(str==""){break;}}
System.IO.StreamReader.ReadLine()就可以了