Home  |  Delphi .net Home  |  System.IO.FileStream  |  Write Method
Write  
Method  
Writes some or all bytes from a Byte Array into the current stream
FileStream Class
System.IO NameSpace
CF1.  Procedure Write ( Bytes:Array of ByteBytes : Array of Byte; ArrayOffset : Integer; Count : Integer; ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
Up to Count bytes are copied from ArrayOffset in the Bytes array to the current position in the stream. The stream position is updated accordingly.
Notes
An exception is raised if the bounds of the Bytes array are exceeded.
Microsoft MSDN Links
System.IO
System.IO.FileStream
 
 
Writing the middle of a Byte array to the current stream
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Stream    : System.IO.FileStream;
  ByteArray : Array of Byte;
  ByteAsInt : Integer;

begin
  // Create out FileStream to write to a text file
  Stream := System.IO.FileStream.Create('C:\DelphiBasics.txt', FileMode.Create);

  // Create our byte array
  SetLength(ByteArray, 10);

  // And fill it
  ByteArray[0] := 65; // Ord(65) = 'A'
  ByteArray[1] := 66;
  ByteArray[2] := 67;
  ByteArray[3] := 68;
  ByteArray[4] := 69;
  ByteArray[5] := 70;
  ByteArray[6] := 71;
  ByteArray[7] := 72;
  ByteArray[8] := 73;
  ByteArray[9] := 74;

  // Now write the middle of the array to the stream
  Stream.Write(ByteArray, 2, 5);

  // Now seek to the start of the stream
  Stream.Seek(0, SeekOrigin.Begin);

  // Now display the contents
  ByteAsInt := Stream.ReadByte;

  while ByteAsInt > 0 do
  begin
    Console.WriteLine(Char(ByteAsInt));
    ByteAsInt := Stream.ReadByte;
  end;

  // Close the stream
  Stream.Close;

  Console.Readline;
end.
Show full unit code
  C
  D
  E
  F
  G
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author