From Free Pascal wiki
A TFileStream is a descendant of TStream that gets/stores its data from/to a file on disk.
|fmCreate||65280||Creates a new file|
|fmOpenRead||0||opens a file for reading|
|fmOpenWrite||1||opens a file for writing|
|fmOpenReadWrite||2||opens a file for reading and writing|
|fmShareDenyWrite||32||prohibit writing if file is already opened|
- read entire file fnam into a string.
function readstream(fnam: string): string; var strm: TFileStream; n: longint; txt: string; begin txt := ''; strm := TFileStream.Create(fnam, fmOpenRead or fmShareDenyWrite); try n := strm.Size; SetLength(txt, n); strm.Read(txt, n); finally strm.Free; end; result := txt; end;
- Write a string txt to the file fnam.
procedure writestream(fnam: string; txt: string); var strm: TFileStream; n: longint; begin strm := TFileStream.Create(fnam, fmCreate); n := Length(txt); try strm.Position := 0; strm.Write(txt, n); finally strm.Free; end; end;