Resolve StreamReader ReadLine left the first character

Posted fred1987

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Resolve StreamReader ReadLine left the first character相关的知识,希望对你有一定的参考价值。

static void FileStreamWriterReadDemo()
        {
            string textFile = "fs.txt";
            using (FileStream fs = new FileStream(textFile, FileMode.Create))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    for (int i = 0; i < 100; i++)
                    {
                        string msg = $"Time:{DateTime.Now.ToString("yyyyMMddHHmmssffff")},Guid:{Guid.NewGuid()}";
                        sw.WriteLine(msg);
                        Thread.Sleep(1);
                    }
                }
            }

            using (StreamReader reader = new StreamReader(textFile))
            {
                string result;
                while (!string.IsNullOrWhiteSpace(result = reader.ReadLine()))
                {
                    Console.WriteLine(result);
                }
            }
        }

The key located at.

 string result;
                while (!string.IsNullOrWhiteSpace(result = reader.ReadLine()))
                {
                    Console.WriteLine(result);
                }

 

以上是关于Resolve StreamReader ReadLine left the first character的主要内容,如果未能解决你的问题,请参考以下文章

StreamReader.Read 和 StreamReader.ReadBlock 之间的区别

当 Stream.Read() 存在时,StreamReader 的目的是啥?

异步延迟 StreamReader.read

使用c#的StreamReader类读取中文乱码

VB.net Streamreader用于不同的潜艇

HTTPWebResponse + StreamReader 非常慢