说明:具体时间没测,但是是试过的几种方式中最快的一种。
bool test(string findkey) { string path = "/ResidentFlash/custinfo/custinfo.txt"; FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("gb2312")); reader.BaseStream.Seek(0L, SeekOrigin.Begin); bool flag=false; while (reader.Peek() >= 0) { try { string str = reader.ReadLine().Trim(); string txtkey = str.Substring(0, 4); if ((str == null) || (str.Length <= 0)) { break; } if (txtkey.Trim() == findkey.Trim()) { reader.Close(); stream.Close(); flag = true;//找到
return flag; } } catch (Exception) { } } if (flag == false)
{
MessageBox.Show("不存在");
} reader.Close(); stream.Close(); return flag; }