Introduction
This application is pretty basic, it uses FileStream
objects to perform its task.
Using the code
ASCIIEncoding Encode = new ASCIIEncoding();
FileStream streamA = File.OpenRead(args[0]);
FileStream streamB = File.OpenRead(args[1]);
long lenA = streamA.Length - 1;
long lenB = streamB.Length - 1;
int byteA;
int byteB;
do
{
byteA = streamA.ReadByte();
byteB = streamB.ReadByte();
if (byteA != byteB)
{
long startPos = streamB.Position;
do
{
byteB = streamB.ReadByte();
}
while (byteA != byteB && streamB.Position <= lenB);
long length = streamB.Position - startPos;
byte[] theseBytes = new byte[length];
streamB.Seek(length * -1, SeekOrigin.Current);|
streamB.Read(theseBytes, 0, (int)length);
Console.WriteLine("Pos:{0}, Len:{1}, Str:{2}", startPos,
length, Encode.GetString(theseBytes));
}
}
while (streamA.Position <= lenA && streamB.Position <= lenB);
streamA.Close();
streamB.Close();
History
- Aug 12, 2009: Written.
- Aug 13, 2009: Rewritten to be more explicit, and I modified the file seeking and some variables to bring this down form 57ms run time to 27ms run time.