您的位置:首页 > 其它

LogPreProcess

2016-04-06 14:09 288 查看
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

using System.Text;

namespace LogPreProcess

{

    class Program

    {

        public static bool isOpen = true;

        public static void Write(string path,string content)

        {

            FileStream fs = new FileStream(path, FileMode.Create);

            StreamWriter sw = new StreamWriter(fs);

            sw.Write(content);

            sw.Flush();

            sw.Close();

            fs.Close();

        }

        public static void Read(string path)

        {

            StreamReader sr = new StreamReader(path, Encoding.Default);

            String line;

            StringBuilder strBuilder = new StringBuilder();

            while ((line = sr.ReadLine()) != null)

            {

                //Console.WriteLine(line.ToString());

                if (line.Contains("[S"))

                {

                    isOpen = false;

                    continue;

                }

                else if (line.Contains("[R"))

                {

                    isOpen = true;

                }

                if (isOpen)

                {

                    strBuilder.Append(line);

                    strBuilder.Append("\r\n");

                }

            }

            string content = strBuilder.ToString();

            Write(path+".txt", content);

        }

        static void Main(string[] args)

        {

            Read(args[0]);

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: