按行讀取文本文檔
??public static long readLog(long length)
??{
???string filename = filePath;//文件路徑
???FGNCDataDeal fgnc = new FGNCDataDeal();
???FileStream mike_stream = new FileStream(filename,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);//打開日志文件
???StreamReader sr = new StreamReader(mike_stream,System.Text.Encoding.GetEncoding("Unicode"));//讀取日志文件
???string output = "";
???long temp_length = 0;
???while(sr.Peek()>0)//傳回下一個(gè)可用的字元,當(dāng)有下一條記錄時(shí)
???{
????temp_length ++;
????output = Strings.StrConv(sr.ReadLine(), VbStrConv.TraditionalChinese, 0x0409);//告警內(nèi)容,將讀取的日志文件內(nèi)容進(jìn)行轉(zhuǎn)換為繁體
???
????//當(dāng)length>=temp_Length或者length=-1時(shí),跳出循環(huán)不讀取數(shù)據(jù);第一次不讀取數(shù)據(jù)
????if (length >=temp_length || length ==-1 || output.Trim() == string.Empty)
????{
?????continue;
????}
????try
????{
?????fgnc.DealData(output,clientIP);???//調(diào)用DealData()方法,處理讀取的日志文件里的數(shù)據(jù)
?????logText(output,"讀取的數(shù)據(jù)");??????//讀取到的告警信息
????}
????catch(Exception ex)
????{
?????logText(ex.ToString()+output,"useDealDataException");
????}
???}
???sr.Close();
???mike_stream.Close();
???if(temp_length<length)
???{
????temp_length=readLog(0);
???}
???return temp_length;//將temp_length的值傳給length
轉(zhuǎn)載于:https://www.cnblogs.com/nofliu/archive/2008/09/23/1296380.html
總結(jié)
- 上一篇: 程序员想进大公司?学会这门编程知识,决定
- 下一篇: 我国自主播放软件暴风影音挑落微软