private void Form1_Load(object sender, EventArgs e)
{
int j=0;
label1.Text= FileRowText(@"c:\update.dat",2, ref j);
}
#region 获取文本某行数据
///
/// 获取文本文件某行数据
/// ///
文本文件路径
///
第几行
///
返回总行数
///
private string FileRowText(string filePath,int i, ref int j)
{
StreamReader sr = File.OpenText(filePath);
string str = "";
string text = "";
int num = 0;
while ((str = sr.ReadLine()) != null)
{
num++;
if (num == i)
{
text = str;
}
}
j = num;
sr.Close();
return text;
}
#endregion
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23109131/viewspace-677923/
,如需转载,请注明出处,否则将追究法律责任。