F.W Create and write in File - JulTob/Ada GitHub Wiki


  --  Create a file and write some text to it.

with text_io; use text_io;
WITH Ada.Directories; USE Ada.Directories;

PROCEDURE WriteFile IS
   FileVar : File_type;   -- File_type is defined in Text_io
BEGIN
   IF Exists( "MYTEXT.TXT" ) THEN
      Put_Line("File already exists");
      RETURN;
   END IF;
   Create( FileVar, Out_file, "MYTEXT.TXT" );
   Put_line( FileVar, "MYTEXT -- A sample text file." );
   Put_line( FileVar, " This program demonstrates how" );
   Put_line( FileVar, " to create and write to a disk" );
   Put_line( FileVar, " text file." );
   Close( FileVar );

   Put_line( "This program created a text file called MYTEXT.TXT");
   Put_line( "in the default directory. It contains the following text:" );
   New_line;
   Put_line( "   MYTEXT -- A sample text file." );
   Put_line( "    This program demonstrates how" );
   Put_line( "    to create and write to a disk" );
   Put_line( "    text file." );
   New_line;
   Put_line( "Open the file with a text editor (eg NOTEPAD) ");
   Put_line( "and check that it contains the above text.");
   New_line;
END;