C# read huge file which size over 20G+

 static void Main(string[] args)
        {
            string fileName = @"logFile3.txt";
            ReadFile(fileName);
            Console.ReadLine();
        }


        static void ReadFile(string fileName)
        {
            long num = 0;
            using (FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            using (BufferedStream bs = new BufferedStream(fs))
            using (StreamReader sr = new StreamReader(bs))
            {
                string str;
                while ((str = sr.ReadLine()) != null)
                {
                    ++num;
                    if(num%100==0)
                    {
                        string[] arr = str.Split(new char[] { '\t' });
                        Console.WriteLine(num);
                        Console.WriteLine(arr[arr.Length-2]);
                    }
                }
            }
        }

 

 

 

 

 

posted @ 2021-06-24 15:35  FredGrit  阅读(52)  评论(0编辑  收藏  举报