開啟並從流檔案中讀取

Create And Write To A Stream 的資料讀回程式。

with Ada.Streams.Stream_IO;

procedure Main is
   --
   --  ... same type definitions as in referenced example
   --
   Fruit_Colors : array (Fruit) of Color;

   use Ada.Streams.Stream_IO;

   F : File_Type;
   X : Fruit;
begin
   Open (F, Mode => In_File, Name => "file.bin");
   loop
      Fruit'Read (Stream (F), X);
      Color'Read (Stream (F), Fruit_Colors (X));
   end loop;
exception
   when End_Error =>
      Close (F);
   pragma Assert  -- check data are the same
     (Fruit_Colors (Banana) = Color'(R => 243, G => 227, B => 18) and
      Fruit_Colors (Orange) = Color'(R => 251, G => 130, B => 51) and
      Fruit_Colors (Pear)   = Color'(R => 158, G => 181, B => 94));
end Main;