ReadWriteFile (Delphi)
Description
This example demonstrates the reading and writing of text files provided by methods of TFile class.
Code
procedure TForm1.btnOpenClick(Sender: TObject);
begin
{ Read text file from given path and write in memo }
try
mmText.Lines[0] := TFile.ReadAllText(edPath.Text);
except
{ Catch the possible exceptions }
MessageDlg('Incorrect path', mtError, [mbOK], 0);
Exit;
end;
end;
procedure TForm1.btnSaveClick(Sender: TObject);
begin
{ Write text from memo to file from given path }
try
TFile.WriteAllText(edPath.Text, mmText.lines.Text);
except
{ Catch the possible exceptions }
MessageDlg('Incorerct path', mtError, [mbOK], 0);
Exit;
end;
end;
Uses
- System.IOUtils.TFile.ReadAllText ( fr | de | ja )
- System.IOUtils.TFile.WriteAllText ( fr | de | ja )