テキストファイルをバイト単位で読込む

あるテキストファイルを nバイトで切り出すってのはよくあることです。Delphiでは BlockRead を使用することで実現できます。
以下のサンプルはテキストファイルを128バイトで切り出し別ファイルに保存します。

■ BlockRead の例
var
   filIn      :    File;
   sltOut     :    TStringList;
   Buff       :    [0..127]  of  char;
   intRead    :    integer;
begin
   AssignFile(filIn,'c:\borland\indata.dat');
   Reset(filIn, 1);
   sltOut   :=   TStringList.Create;
   sltOut.Clear;
   while  not  Eof(filIn)  do  begin
      BlockRead(filIn,Buff,SizeOf(Buff),intRead);   
      sltOut.Add(Buff);
   end;
   sltOut.SaveToFile('c:\borland\outdata.dat');
   sltOut.Free;
   CloseFile(filIn);
end;