Not sure if this meets your requirements, but it works fast too.
var aFile: TFileStream; const FileAddr: String = 'H:\Akon.mp3'; begin if FileExists(FileAddr) then begin aFile:= TFileStream.Create(FileAddr, fmOpenReadWrite); try afile.Size := 0; finally aFile.Free; ShowMessage('Finish'); end; end; end;
So there will be something in this direction (declaring b outside the function will improve your loop performance, especially when working with a large file). I assume that the application filename will have var :
const b: byte=0; procedure MyProc; var aFile: TFileStream; Buf: array of byte; len: integer; FileAddr: String; begin FileAddr := 'C:\testURL.txt'; if FileExists(FileAddr) then begin aFile := TFileStream.Create(FileAddr, fmcreate); try len := afile.Size; setlength(buf, len); fillchar(buf[0], len, b); aFile.Position := 0; aFile.Write(buf, len); finally aFile.Free; ShowMessage('Finish'); end; end; end;
source share