unit FileRead;
interface
uses
Classes, SysUtils;
type
TFileReadThread = class(TThread)
private
{ Private declarations }
FFileName:String;
FOutFile:String;
FStart:Integer;
FLen:Integer;
protected
procedure Execute; override;
public
constructor Create (FileName,OutFile:String;Start,Len:Integer);
end;
implementation
{ TFileReadThread }
constructor TFileReadThread.Create(FileName,OutFile: String; Start, Len: Integer);
begin
FFileName := FileName;
FOutFile :=OutFile;
FStart := Start;
FLen := Len;
FreeOnTerminate := True;
Inherited Create(false);
end;
procedure TFileReadThread.Execute;
var
InStream,OutStream:TStream;
buf:Array of Byte;
begin
{ Place thread code here }
InStream := TFileStream.Create(FFileName,fmOpenRead or fmShareDenyWrite);
OutStream := TFileStream.Create(FOutFile,fmCreate);
SetLength(Buf,FLen);
InStream.Seek(FStart,soFromBeginning);
FLen := InStream.Read(Buf[0],FLen);
OutStream.Write(Buf[0],FLen);
OutStream.Free;
InStream.Free;
end;
end.
//调用:const
LINELEN = 1;
var
i:Integer;
Len:Integer;
fstr:TStream;
begin
fStr := TFileStream.Create('E:\OldTree\a\a.txt',fmOpenRead or fmShareDenyWrite);
Len := (Trunc(((fStr.Size / 10) / (LINELEN +2))) +1) * (LINELEN + 2);
//设置Len为一行的整数倍,注意CR/LF为两个字符.
for i:=0 to 9 do
TFileReadThread.Create('E:\OldTree\a\a.txt','E:\OldTree\a\a' + IntToStr(i) + '.txt',i*Len,Len);
fstr.Free;
end;
阅读(1023) | 评论(0) | 转发(0) |