Home  |  Delphi .net Home  |  System.IO.File  |  OpenRead Method
  
OpenRead  
Method  
Opens the specified file for the read only access
File Class
System.IO NameSpace
CF1.  Function OpenRead ( PathString : String ) : FileStream; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns a FileStream object allowing the file specified in PathString to be read only.
References
FileStream
Microsoft MSDN Links
System.IO
System.IO.File
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Path   : String;
  Stream : System.IO.FileStream;
  MyByte : Integer;

begin
  // Open the file for writing
  Path := 'C:\DelphiBasics.txt';
  Stream := System.IO.File.OpenWrite(path);

  // Write to the file
  Stream.WriteByte(65);  // Chr(65) = 'A'
  Stream.WriteByte(66);  // Chr(66) = 'B'
  Stream.WriteByte(67);  // Chr(67) = 'C'

  // Close the file
  Stream.Close;

  // Re-open for reading
  Stream := System.IO.File.OpenRead(Path);

  // Display the contents
  MyByte := Stream.ReadByte;
  while MyByte >= 0 do
  begin
    Console.Write(Char(MyByte));
    MyByte := Stream.ReadByte;
  end;

  // Close the stream
  Stream.Close;

  Console.Readline;
end.
   ABC
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author