Google
 

Friday, August 22, 2008

Delphi: Reading and writing a file to and from a string

Reading a file to a string

Perhaps the easiest way to read a file into a string is using the LoadFromFile method of a TStringList object and then accessing its Text property:

uses SysUtils, Classes;

function LoadFile(const FileName: TFileName): string;
begin
with TStringList.Create do
try
LoadFromFile(FileName);
Result := Text;
finally
Free;
end;
end;

No comments: