Description |
A StreamWriter object is returned allowing write access to the file specified in PathString, position starting at the end of the current file contents.
|
| References | StreamWriter
|
|
Microsoft MSDN Links |
System.IO
System.IO.File
|
|
|
A simple example |
program Project1;
{$APPTYPE CONSOLE}
uses
System.IO;
var
Path : String;
Reader : System.IO.StreamReader;
Writer : System.IO.StreamWriter;
MyByte : Integer;
begin
// Open the file for writing
Path := 'C:\DelphiBasics.txt';
Writer := System.IO.File.CreateText(Path);
// 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 := System.IO.File.AppendText(Path);
// Write some more lines to the file
Writer.Write('D');
Writer.Write('E');
// Close the file
Writer.Close;
// Re-open for reading
Reader := System.IO.File.OpenText(Path);
// Display the contents
Console.WriteLine(Reader.ReadToEnd);
// Close the file
Reader.Close;
Console.Readline;
end.
| Show full unit code | ABCDE
|
|
|
|