Write entire file: Difference between revisions
Content added Content deleted
(=={{header|Racket}}== implementation added) |
|||
Line 10: | Line 10: | ||
The reverse of [[Read entire file]]—for when you want to update or create a file which you would read in its entirety all at once. |
The reverse of [[Read entire file]]—for when you want to update or create a file which you would read in its entirety all at once. |
||
=={{header| |
=={{header|Ada}}== |
||
<lang Ada>with Ada.Text_IO; use Ada.Text_IO; |
|||
procedure Write_Whole_File is |
|||
F: File_Type; |
|||
File_Name : String := "the_file.txt"; |
|||
Contents: String := "(Over)write a file so that it contains a string. " & |
|||
"The reverse of Read entire file—for when you want to update or " & |
|||
"create a file which you would read in its entirety all at once."; |
|||
begin |
|||
begin |
|||
Open(F, Mode => Out_File, Name => File_Name); -- overwrite existing file |
|||
exception |
|||
when Name_Error => -- file does not yet exist |
|||
Create (F, Mode => Out_File, Name => File_Name); -- write new file |
|||
end; |
|||
Put (F, Contents); |
|||
Close (F); |
|||
end Write_Whole_File;</lang> |
|||
=={{header|J}}== |
|||
<lang J> characters fwrite filename</lang> |
<lang J> characters fwrite filename</lang> |
||