I think we often want to compare a file inside whether there are changes, such as a DLL library is a new method or modify the implementation of the method, can not be compared by the visual tools to compare, the use of this gadget to compare, the following is the code to compare files.
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.IO;namespacefilescompare{classProgram {Static voidMain (string[] args) {Console.WriteLine ("Please type the first file."); stringFirstfilepath =Console.ReadLine (); Console.WriteLine ("Please type the second file."); stringSecondfilepath =Console.ReadLine (); BOOLIsEqual =comparefiles (Firstfilepath, Secondfilepath); Console.WriteLine (IsEqual?"Equal":"Not equal"); Console.read (); } Public Static BOOLComparefiles (stringTargetFile,stringupdatedfile) {FileInfo Targetfileinfo=NewFileInfo (targetfile); FileInfo Updatedfileinfo=NewFileInfo (Updatedfile); if(Targetfileinfo.length! =updatedfileinfo.length) {return false; } using(FileStream Targetstream =File.openread (targetfile)) { using(FileStream Updatedstream =File.openread (Updatedfile)) { if(Targetstream.length! =updatedstream.length) {return false; } //Using a larger buffer than the default buffer of 4 * 1024x768 used by Filestream.readbyte improves performance. //The buffer size is based on user feedback. Based on performance results, a better buffer size could be determined. byte[] Targetbuffer =New byte[ -*1024x768]; byte[] Updatedbuffer =New byte[ -*1024x768]; inttargetreadlength; intupdatedreadlength; Do{targetreadlength= Targetstream.read (Targetbuffer,0, targetbuffer.length); Updatedreadlength= Updatedstream.read (Updatedbuffer,0, updatedbuffer.length); if(Targetreadlength! =updatedreadlength) { return false; } for(inti =0; i < targetreadlength; ++i) {if(Targetbuffer[i]! =Updatedbuffer[i]) { return false; } } } while(0<targetreadlength); } } return true; } }}
C # File Comparison code