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
|
|
|
|