Home  |  Delphi .net Home  |  System.IO.FileInfo  |  OpenText Method
  
OpenText  
Method  
Opens the current file for reading as a text file
FileInfo Class
System.IO NameSpace
CF1.  Function OpenText : StreamReader;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns a StreamReader object that allows the current file to be read as a text file.
References
StreamReader
Microsoft MSDN Links
System.IO
System.IO.FileInfo
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
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.FileStream;
  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.OpenWrite;

  // Write to the file
  Writer.WriteByte(65);  // Chr(65) = 'A'
  Writer.WriteByte(66);  // Chr(66) = 'B'
  Writer.WriteByte(67);  // Chr(67) = '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.
   ABC
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author