In fact, if you want to compare two test, you can do as following, 1. load each files into a variant, just read the file every bit and save it to a block of memory. 2. test whether the two variant is same, if same, the files are same, otherwise on not.
首先,定义filestream1和filestream2两个变量 然后定义 buffer1,buffer2:array[0..99] of char;两个长度为100的缓冲区 循环读取和比较就可以了 代码如下 写得比较仓促,没有注释,请原谅var i : Integer; num1,num2:Integer; IsSame:Boolean; begin num1:=1; num2:=1; IsSame:=TRUE; file1:=TFileStream.Create('g:\asd.txt',fmOpenRead); file2:=TFileStream.Create('g:\asd1.txt',fmOpenRead); while (num1<>0)or(num2<>0) do begin ZeroMemory(@bf1,100); ZeroMemory(@bf2,100); num1:=file1.Read(bf1,100); num2:=file2.Read(bf2,100); for i:=0 to 99 do begin if bf1[i]<>bf2[i] then IsSame:=FALSE; end; end; if IsSame then MessageBox(0,'相同',nil,0) else MessageBox(0,'不相同',nil,0); end;
如果你想自己编程实现,就循环读文件并判断啰!
1. load each files into a variant, just read the file every bit and save it to a block of memory.
2. test whether the two variant is same, if same, the files are same, otherwise on not.
然后定义 buffer1,buffer2:array[0..99] of char;两个长度为100的缓冲区
循环读取和比较就可以了
代码如下
写得比较仓促,没有注释,请原谅var
i : Integer;
num1,num2:Integer;
IsSame:Boolean;
begin
num1:=1;
num2:=1;
IsSame:=TRUE;
file1:=TFileStream.Create('g:\asd.txt',fmOpenRead);
file2:=TFileStream.Create('g:\asd1.txt',fmOpenRead);
while (num1<>0)or(num2<>0) do
begin
ZeroMemory(@bf1,100);
ZeroMemory(@bf2,100);
num1:=file1.Read(bf1,100);
num2:=file2.Read(bf2,100);
for i:=0 to 99 do
begin
if bf1[i]<>bf2[i] then IsSame:=FALSE;
end;
end;
if IsSame then
MessageBox(0,'相同',nil,0)
else
MessageBox(0,'不相同',nil,0);
end;