ループ内で TFileStream.Read を使用してテキスト ファイルを読み取っていますが、最後の部分がバッファに読み取られていないことがわかりました。ただし、読み取られる合計バイト数はファイル サイズと同じです。
これは私のコードです:
procedure TForm1.DoImport;
var
f: String;
fs: TFileStream;
r, c: Integer;
buf: TBytes;
const
bufsiz = 16384;
begin
SetLength(buf, bufsiz);
f := 'C:\Report\Claims\Claims.csv';
fs := TFileStream.Create(f, fmOpenRead);
try
c := 0;
repeat
r := fs.Read(buf, bufsiz);
Inc(c, r);
until (r <> bufsiz);
showmessage('Done. ' + IntToStr(c)); // <-- c equals to filesize !!
Memo1.Text := StringOf(buf); // <-- but the memo does not show the last chunk of the file
finally
fs.Free;
end;
end;
最後に、TMemo にはファイルの最後のチャンクは含まれませんが、最後から 2 番目のチャンクが含まれます。私のコードに何か問題がありますか?
前もって感謝します!