/// <summary>
/// 读取Text文件,把数据存放到DataTable
/// </summary>
/// <param name="dt">存放数据的DataTable</param>
/// <param name="TextFile">Text文件名</param>
public static void ReadTextFile(ref DataTable dt, string TextFile)
{
dt.Rows.Clear();
if (System.IO.File.Exists(TextFile))
{
System.IO.FileStream fs = new System.IO.FileStream(TextFile, System.IO.FileMode.Open);
System.IO.StreamReader m_streamReader = new System.IO.StreamReader(fs, System.Text.Encoding.Default);
//m_streamReader.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
string strLine = m_streamReader.ReadLine();
//读取文件内容
while (!string.IsNullOrEmpty(strLine))
{
DataRow drNew = dt.NewRow();
string[] arrItem = strLine.Split(new char[] { splitStr }, StringSplitOptions.None);
for (int i = 0; i < arrItem.Length; i++)
{
if (i < dt.Columns.Count)
{
drNew[i] = arrItem[i];
}
else
{
break;
}
}
dt.Rows.Add(drNew);
strLine = m_streamReader.ReadLine();
}
m_streamReader.Close();
}
}