public void _DoProcessFileNomal(System.String strDataSrcFile, System.String strDataDestFile) { System.IO.StreamReader fileReadHander = null; System.IO.StreamWriter fileWriterHander = null; System.Int32 nIndexContainKey = -1; m_strDataSrcFile = strDataSrcFile; m_strDataDestFile = strDataDestFile; //System.IO.FileInfo fileinfo = new System.IO.FileInfo(strDataSrcFile); fileReadHander = new System.IO.StreamReader(strDataSrcFile); fileWriterHander = new System.IO.StreamWriter(strDataDestFile); System.String strGetLineSrc = System.String.Empty; // Read and display lines from the file until the end of // the file is reached. while ((strGetLineSrc = fileReadHander.ReadLine()) != null) { if (true == m_bNomalInsertKeyInclue) { nIndexContainKey = m_LineFindKeyIndex.findUPKeyIndexInUPLine(strGetLineSrc, m_Key_jin_include_space_StdAfxh); if (-1 != nIndexContainKey) { _ProcessEachLine(strGetLineSrc, fileWriterHander); continue; } nIndexContainKey = m_LineFindKeyIndex.findKeyIndexInLine(strGetLineSrc, m_Key_jin_include_tab_StdAfxh); if (-1 != nIndexContainKey) { _ProcessEachLine(strGetLineSrc, fileWriterHander); continue; } nIndexContainKey = m_LineFindKeyIndex.findKeyIndexInLine(strGetLineSrc, m_Key_jin_include_space); if (-1 != nIndexContainKey) { fileWriterHander.WriteLine(m_str_key_include_type); m_bNomalInsertKeyInclue = false; } } _ProcessEachLine(strGetLineSrc, fileWriterHander); }//end while fileReadHander.Close(); fileWriterHander.Close(); }
/// <summary> /// /// </summary> /// <param name="strFullPath"></param> /// <param name="strFindKey"></param> /// <returns>-1 or 1 2 3</returns> public System.Int32 findKeyLineIndex(System.String strFullPath, System.String strFindKey) { System.IO.StreamReader fileReadHander = null; System.Int32 nLineInFileIndex = -1; System.Int32 nKeyInLineIndex = -1; System.Boolean bFindKey = false; fileReadHander = new System.IO.StreamReader(strFullPath); System.String strGetLineSrc = System.String.Empty; // Read and display lines from the file until the end of // the file is reached. nLineInFileIndex = 1; bFindKey = false; while ((strGetLineSrc = fileReadHander.ReadLine()) != null) { //check each line nKeyInLineIndex = m_LineFindKeyIndex.findKeyIndexInLine(strGetLineSrc, strFindKey); if (-1 != nKeyInLineIndex) { bFindKey = true; break; } nLineInFileIndex++; } fileReadHander.Close(); if (false == bFindKey) { nLineInFileIndex = -1; } return(nLineInFileIndex); }