In Ada, why are my attempts to open a file for writing failing?
When I attempt to open a file to write to I get an Ada.IO_Exceptions.N开发者_StackOverflow中文版ame_Error.
The file name is "C:\CC_TEST_LOG.TXT". This file does not exist.
This is on Windows XP on an NTFS partition. The user has permissions to create and write to the directory. The filename is well under the WIN32 max path length.
name_2 : String := "C:\CC_TEST_LOG.TXT"
if name_2'last > name_2'first then
begin
Ada.Text_IO.Create(file, Ada.Text_IO.Out_File, name_2);
Ada.Text_IO.Put_Line(
"CC_Test_Utils: LogFile: ERROR: Open, File "
& name_2);
return;
exception
when The_Error : others =>
Ada.Text_IO.Put_Line(
"CC_Test_Utils: LogFile: ERROR: Open Failed; "
& Ada.Exceptions.Exception_Name(The_Error)
& ", File " & name_2);
end;
end if;
Off the top of my head:
- At the time
Create
is called,file
isn't already associated with another open file is it? - What compiler are you using? Gnat is mingw-based, and might not like the windows "C:\" designator. Try taking that part out and see if it creates the file (somewhere).
- As Xandy mentioned, the file might already be opened by another program. That
Create
call requires exclusive access to the file.
As an aside, what is the point of that Put_Line right after the Create
? Is successfully opening the file also an error for some reason? It seems like it could perhaps be misleading, making one think the program failed to open the file when it actually succeeded.
精彩评论