usingSystem;usingSystem.IO;usingSystem.Linq;usingSystem.Text;namespacetestmultyconsole2{ Public classLocalfilehelper {/// <summary> ///Delete some data from a large log file/// </summary> /// <param name= "FilePath" >source file path</param> /// <param name= "Newfilepath" >Destination file path</param> /// <param name= "key" >Delete data between keys (contains key)</param> /// <param name= "words" >Delete a row of data that contains the data in the list</param> Public Static voidCopycontentanddeletesomething (stringFilePath,stringNewfilepath,stringKeystring[] words) { BOOLFlag =false;//identifiers LongCount =0;//counter using(StreamReader sr =NewStreamReader (FilePath, Encoding.GetEncoding ("gb2312"))) using(StreamWriter StreamWriter =NewStreamWriter (Newfilepath,true, Encoding.GetEncoding ("gb2312"))) { while(Sr.) Peek () >=0) { stringTMP =Sr. ReadLine (); if(TMP! =NULL&&tmp. Contains (key)) {flag= !Flag; } if(!flag &&!)iscontains (TMP, words)) streamwriter.writeline (TMP); if(count++%10000==0) Console.WriteLine (Count/10000); }} Console.WriteLine ("Total {0} rows of data", Count); } /// <summary> ///determine if the value in keys is included in the content/// </summary> /// <param name= "Content" >Data Source</param> /// <param name= "Keys" >Key List</param> /// <returns></returns> Public Static BOOLIscontains (stringContentstring[] keys) { returnKeys! =NULL&&keys. Any (content. Contains); } }}
Delete a piece of data from a large log file