Home  |  Delphi .net Home  |  System.IO.StreamWriter  |  Close Method
Close  
Method  
Closes the StreamWriter
StreamWriter Class
System.IO NameSpace
CF1.  Procedure Close ( ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
Closes the StreamWriter stream, calling the Dispose method to do so.
 
After closing the writer, an exception will be thrown if you try to write to it again.
Microsoft MSDN Links
System.IO
System.IO.StreamWriter
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Reader : System.IO.StreamReader;
  Writer : System.IO.StreamWriter;

begin
  // Create our Stream Writer to write to a text file
  Writer := System.IO.StreamWriter.Create('C:\DelphiBasics.txt');

  // Write various things to our StreamWriter
  Writer.WriteLine(27);
  Writer.WriteLine(true);
  Writer.WriteLine(DateTime.Create(2004, 9, 17));

  // Close the writer
  Writer.Close;

  // Create our StreamReader
  Reader := System.IO.StreamReader.Create('C:\DelphiBasics.txt');

  // Now display the file contents
  Console.WriteLine(Reader.ReadToEnd);

  // Close the reader
  Reader.Close;

  Console.Readline;
end.
Show full unit code
  27
  True
  17/09/2004 00:00:00
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author