function TFORM1.TEST;VARFS:TFILESTREAM;FS2:TFILESTREAM;FS3:TFILESTREAM;STR:STRING;MS:TMEMORYSTREAM;MS2: Tmemorystream;sr:tstream;begin//tfilestream Create a text file str:= ' file operation '; Fs:=tfilestream.create (' C:\1.txt ', fmcreate); Fs. WriteBuffer ((PChar (str)) ^,length (str)); Fs. Free; TFileStream Read text file fs:=tfilestream.create (' C:\1.txt ', fmopenread); SetLength (str,fs.size); Fs. Readbuffer ((PChar (str)) ^,fs. Size); ShowMessage (str); Fs. Free; TFileStream read text file ms:=tmemorystream.create; Ms. LoadFromFile (' C:\1.txt '); SetLength (str,ms.size); Ms. Readbuffer ((PChar (str)) ^,ms.size); Ms. Free; ShowMessage (str); Tmemorystream Create text file str:= ' file operation '; Ms:=tmemorystream.create; Ms. WriteBuffer ((PChar (str)) ^,length (str)); Ms. SaveToFile (' C:\2.txt '); Ms. Free; Tmemorystream file merging ms:=tmemorystream.create; Ms. LoadFromFile (' C:\1.txt '); Ms. Position:=ms. size;//move file pointer ms2:=tmemorystream.create; MS2. LoadFromFile (' C:\2.txt '); Ms. CopyFrom (ms2,0); Ms. SaveToFile (' C:\3.txt '); Ms. Free; MS2. Free;end;
TFileStream and Tmemorystream read, create, and merge files separately