-1

StreamReader.EndOfStreamusing和 string != null in 文件处理 有什么区别

using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line;
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}






 while (!reader.EndOfStream)
            {
                data = BreakLine(line);
                DataRow dr = _DataTable.NewRow();
                // protect against overflow
                int maxColumns = Math.Min(_DataTable.Columns.Count, data.Length);
                for (int i = 0; i < maxColumns; i++)
                {
                    dr[i] = data[i];
                }
                _DataTable.Rows.Add(dr);
                line = reader.ReadLine();
            }
4

1 回答 1

1

这两个处理不同的情况。如果您对文件进行操作,EOF将表明您的文件指针已到达文件末尾,而 aStream是连续的数据流(通常是单向的,而不是您通常可以随机访问的文件)。

这里它说关于文件

"The easiest way to think about a file is as a linear sequence of characters."

关于它说的流

"We can think of a stream as a channel or conduit on which data is passed from senders to receivers."

阅读文章以获得印象。虽然是约C++,但很好地反映了基础知识。

于 2013-04-02T07:04:39.993 回答