C#StreamReader读文件,怎么样得到文件里项目个数?
数据文件类似于这样子
A,B,C,D,E
F,G,H,I,J
K,L,M,N,O
.....
每一行的个数都是一样的,现在要得到它一行的具体项目个数
代码如下:
DataTable dt = new DataTable();
DataRow row = null;
string lineData = null;
string [] split = null;
try
{
StreamReader sr = new StreamReader(File.OpenRead(strCsvPath), System.Text.Encoding.Default);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
for (int k = 0; k < 5; k++)
{
dt.Columns.Add(k.ToString());
}
while (sr.Peek() > -1)
{
row = dt.NewRow();
lineData = sr.ReadLine();
split = lineData.Split(new char[] { ', ' });
for (int l = 0; l < 5; l++)