在 Ada 中,为什么我尝试打开文件进行写入失败?
当我尝试打开要写入的文件时,出现 Ada.IO_Exceptions.Name_Error。
文件名为“C:\CC_TEST_LOG.TXT”。该文件不存在。
这是在 Windows XP 上的 NTFS 分区上。用户具有创建和写入目录的权限。 文件名远低于 WIN32 最大路径长度。
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;
When I attempt to open a file to write to I get an Ada.IO_Exceptions.Name_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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我突然想到:
Create
时,file
尚未与另一个打开的文件关联,是吗?Create
调用需要对该文件的独占访问权限。顺便说一句,
Create
之后的 Put_Line 有何意义? 成功打开文件是否也会由于某种原因出现错误?看起来它可能会产生误导,让人认为程序实际上成功打开了文件却失败了。Off the top of my head:
Create
is called,file
isn't already associated with another open file is it?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.