I am trying to read a text file using the code (pasted below), but the last line of the file does not get read. Is my logic correct?
using (StreamReader reader = new StreamReader(stream))
{
try
{
string line = reader.ReadLine();
string[] data = BreakLine(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();
}
return _DataTable;
}
finally
{
reader.Close();
reader.Dispose();
stream.Close();
}
}