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); }