Home  |  Delphi .net Home  |  System.IO.FileInfo  |  AppendText Method
AppendText  
Method  
Returns a StreamWriter object allowing appending to the current text file
FileInfo Class
System.IO NameSpace
CF1.  Function AppendText ( ) : StreamWriter;
CF : Methods with this mark are Compact Framework Compatible
Description
A StreamWriter object is returned allowing write access to the current file, position starting at the end of the current file contents.
References
StreamWriter
Microsoft MSDN Links
System.IO
System.IO.FileInfo
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  FileInfo : System.IO.FileInfo;
  Reader   : System.IO.StreamReader;
  Writer   : System.IO.StreamWriter;
  MyByte   : Integer;

begin
  // Create a FileInfo object for a text file
  FileInfo := System.IO.FileInfo.Create('C:\DelphiBasics.txt');

  // Open the file for writing
  Writer := FileInfo.CreateText;

  // Write to the file
  Writer.Write('A');
  Writer.Write('B');
  Writer.Write('C');

  // Close the file
  Writer.Close;

  // Open the file for appending to
  Writer := FileInfo.AppendText;

  // Write some more lines to the file
  Writer.Write('D');
  Writer.Write('E');

  // Close the file
  Writer.Close;

  // Re-open for reading
  Reader := FileInfo.OpenText;

  // Display the contents
  Console.WriteLine(Reader.ReadToEnd);

  // Close the file
  Reader.Close;

  Console.Readline;
end.
Show full unit code
  ABCDE
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author