RosettaCodeData/Task/Write-entire-file/Free-Pascal-Lazarus/write-entire-file.pas
2023-07-01 13:44:08 -04:00

20 lines
586 B
ObjectPascal

program overwriteFile(input, output, stdErr);
{$mode objFPC} // for exception treatment
uses
sysUtils; // for applicationName, getTempDir, getTempFileName
// also: importing sysUtils converts all run-time errors to exceptions
resourcestring
hooray = 'Hello world!';
var
FD: text;
begin
// on a Debian GNU/Linux distribution,
// this will write to /tmp/overwriteFile00000.tmp (or alike)
assign(FD, getTempFileName(getTempDir(false), applicationName()));
try
rewrite(FD); // could fail, if user has no permission to write
writeLn(FD, hooray);
finally
close(FD);
end;
end.