• 按行讀取文本文檔


      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)//傳回下一個可用的字元,當有下一條記錄時
       {
        temp_length ++;
        output = Strings.StrConv(sr.ReadLine(), VbStrConv.TraditionalChinese, 0x0409);//告警內容,將讀取的日志文件內容進行轉換為繁體
       
        //當length>=temp_Length或者length=-1時,跳出循環不讀取數據;第一次不讀取數據
        if (length >=temp_length || length ==-1 || output.Trim() == string.Empty)
        {
         continue;
        }

        try
        {
         fgnc.DealData(output,clientIP);   //調用DealData()方法,處理讀取的日志文件里的數據
         logText(output,"讀取的數據");      //讀取到的告警信息
        }

        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

  • 相关阅读:
    有用的Python模块
    Python中for循环搭配else的陷阱
    MySQL实用操作
    Pycharm常用快捷键
    MySQL基础
    HTML基础
    MySQL基础
    HTTP连接管理
    TCP连接的建立和终止
    TCP数据流
  • 原文地址:https://www.cnblogs.com/nofliu/p/1296380.html
Copyright © 2020-2023  润新知