留
留香客
Unregistered / Unconfirmed
GUEST, unregistred user!
读文件到动态数组老不成功,静态就可以,奇怪。
Var
res : boolean;
bytestoread, numread: longword;
handle : THandle;
a : Array Of byte;
buf : Pointer;
t : TFileStream;
Begin
SetLength(a,10000);
handle := CreateFile(pchar('c:/1.rar'), GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE,
Nil, OPEN_EXISTING,0, 0);
bytestoread := 10000;
res := ReadFile(handle, a,bytestoread, numread, Nil);
t := TFileStream.Create('c:/1.txt', fmCreate Or fmOpenWrite);
t.WriteBuffer(a, 10000);
t.Free;
CloseHandle(handle);
end;
Var
res : boolean;
bytestoread, numread: longword;
handle : THandle;
a : Array Of byte;
buf : Pointer;
t : TFileStream;
Begin
SetLength(a,10000);
handle := CreateFile(pchar('c:/1.rar'), GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE,
Nil, OPEN_EXISTING,0, 0);
bytestoread := 10000;
res := ReadFile(handle, a,bytestoread, numread, Nil);
t := TFileStream.Create('c:/1.txt', fmCreate Or fmOpenWrite);
t.WriteBuffer(a, 10000);
t.Free;
CloseHandle(handle);
end;