我想了解为什么当 console.writeline 输出这个来自字符串变量的文本时会有换行符。“现在是所有好人的时候了”。
String filename = @"C:\data\chars.txt";
TextWriter aText = File.AppendText(filename);
String lineToWrite = "Now is the time for all good people";
aText.WriteLine(lineToWrite);
aText.Close();
StreamReader aStream = new StreamReader(filename);
string words = "";
char letter;
while (aStream.Peek() != -1)
{
letter = Convert.ToChar(aStream.Read());
Console.WriteLine(letter);
words += letter;
}
aStream.Close();
Console.WriteLine(words);
Console.ReadKey();
控制台 writeline 只调用一次,但终端屏幕逐行显示字符串,当文件中有 3 行时,所以如果我再次运行它,屏幕上将有 4 行,每行都有自己的行,在哪里换行符从何而来?