用流读取文本文件,记住读取的结束位置,下次直接从该处读取,可是好像没有实现:
private void butopen_Click(object sender, System.EventArgs e)
{
///打开日志。默认500行。
//判断输入字符是不是整数。
Regex r = new Regex("\\D");
Match m = r.Match(tBoxone.Text);
Regex r1 = new Regex("\\D");
Match m1 = r1.Match(tBoxbegincount.Text);
if ((m.Success) ||(m1.Success))
{
string message = "输入的读取的行数不是数字!";
string caption = "错误提示";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(this, message, caption, buttons);
}
//判断输入字符是不是整数。
else
{
if(oFDialog.ShowDialog() == DialogResult.OK)
{
lBoxlog.Items.Clear(); //清空显示内容。
string path=oFDialog.FileName;
sr = new StreamReader(path);
//using (sr = new StreamReader(path))
// int nowcount=1;
fmFirelog.ActiveForm.Text=System.Convert.ToString(DateTime.Now);
//记录开始读取的时间。
int bcount=int.Parse(tBoxbegincount.Text);
//从bcount开始读取。
int endcount=bcount+int.Parse(tBoxone.Text);
//读到endcount。
for (int i = 1; i <= endcount; i++)
{
if ((i>=bcount)&&(sr.Peek()!=-1))
{
lBoxlog.Items.Add(sr.ReadLine());
}
else
{
sr.ReadLine();
}
nowcount++;
}
labelnowingcount.Text=System.Convert.ToString(DateTime.Now);
tBoxbegincount.Text=System.Convert.ToString(nowcount);
}
}
}
private void butNext_Click(object sender, System.EventArgs e)
{
// *************** 这里总是直接退出了。难道打开的文件已经变成空了么?
if (sr.Peek()!=-1) { return;}
// *************** 这里总是直接退出了。难道打开的文件已经变成空了么?
Regex r = new Regex("\\D");
Match m = r.Match(tBoxone.Text);
Regex r1 = new Regex("\\D");
Match m1 = r1.Match(tBoxbegincount.Text);
if ((m.Success) ||(m1.Success))
{
string message = "输入的读取的行数不是数字!";
string caption = "错误提示";
MessageBoxButtons buttons = MessageBoxButtons.OK;
MessageBox.Show(this, message, caption, buttons);
return;
}
int endcount=int.Parse(tBoxone.Text); //读到endcount。
for (int i = 1; i <= endcount; i++)
{
lBoxlog.Items.Add(sr.ReadLine());
nowcount++;
}
tBoxbegincount.Text=System.Convert.ToString(nowcount);
}
}
}