日期:2014-05-18 浏览次数:21105 次
string sTestFileName = @"e:\t1.txt";
int iInsertLine = 5;
string sInsertText = "插入的内容";
string sText = "";
System.IO.StreamReader sr = new System.IO.StreamReader(sTestFileName);
int iLnTmp = 0; //记录文件行数
while (!sr.EndOfStream)
{
    iLnTmp++;
    if (iLnTmp == iInsertLine)
    {
        sText += sInsertText + "\r\n";  //将值插入
    }
    string sTmp = sr.ReadLine();    //记录当前行
    sText += sTmp+"\r\n";
}
sr.Close();
System.IO.StreamWriter sw = new System.IO.StreamWriter(sTestFileName, false);
sw.Write(sText);
sw.Flush();
sw.Close();