目标文件:
Hello
World
代码:
if (file != null)
{
//Read file one character at a time
StreamReader reader;
reader = new StreamReader(file);
do
{
int s = reader.Read();
char sC = (char)s;
if (sC.Equals(Environment.NewLine))
{
Console.WriteLine("+1");
}
Console.WriteLine((char)s);
} while (!reader.EndOfStream);
reader.Close();
reader.Dispose();
}
输出:
H
e
l
l
o
W
o
r
l
d
因此(sC.Equals(Environment.NewLine))
,一次读取一个字符时显然没有检测到与平台无关的换行符..我该怎么做?