Home  |  Delphi .net Home  |  System.IO.FileInfo  |  CreateText Method
CreateText  
Method  
Cerates a StreamWriter object allowing write access the current file
FileInfo Class
System.IO NameSpace
CF1.  Function CreateText ( ) : StreamWriter;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns a StreamWriter object that allows the current file to be written to as a text file.
References
StreamWriter
Microsoft MSDN Links
System.IO
System.IO.FileInfo
 
 
Open a file for writing and then write to it and read from it
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;

  // 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
  ABC
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author