本文介绍了在调用fopen之前是否存在文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 那里, 我试图使用以下方法附加二进制文件: FILE * strean; stream = fopen(" c:\ temp.dat"," ba +")); 我有办法吗? fopen之前可以检查文件是否存在,因为我会通过检查 状态来调用不同的工作流程吗? 提前致谢,Hi, there,I am trying to append a binary file by using:FILE *strean;stream = fopen( "c:\temp.dat", "ba+" ));Is there a way that I can check if the file exists or not beforefopen, because I will call different work flow by check the status ofthe file?Thanks in advance,推荐答案 您可以尝试以只读模式打开文件,然后再次打开 ,在您知道结果后再追加第一个操作。 (或使用系统特定的机制来读取目录等) 请注意,如果环境是多任务的系统,和文件的存在取决于另一个程序,没有办法(在 标准C中)保证文件不是由某人创建的两个fopen()调用之间的 else。 Roberto Waltman [请回复小组, 返回地址无效]You can attempt to open the file in read-only mode, and then open itagain for appending after you know the result of the first operation.(Or use a system-specific mechanism to read the directory, etc.)Be aware that if environment is a multi-tasking system, and theexistence of the file depends on another program, there is no way (instandard C) of guaranteeing that the file was not created by somebodyelse between the two fopen() calls.Roberto Waltman[ Please reply to the group,return address is invalid ] 这是一个非常奇特的文件名。您可能希望 在comp.lang.c中查看问题19.17常见问题 问题(FAQ)列表位于< http://c-faq.com/在你去之前 更进一步。That''s a very peculiar file name. You might want toreview Question 19.17 in the comp.lang.c Frequently AskedQuestions (FAQ) list at <http://c-faq.com/before you gomuch further. ...这是问题19.11。 - Eric Sosman es*****@acm-dot-org.inva 盖子 致电后fopen withba +,使用ftell查看你的位置。 - Fred L. Kleinschmidt 波音助理技术研究员 航空稳定性与控制计算After you call fopen with "ba+", use ftell to see where you are.--Fred L. KleinschmidtBoeing Associate Technical FellowAero Stability and Controls Computing 这篇关于在调用fopen之前是否存在文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 17:45
查看更多