iOS中的fopen问题 [英] fopen issue in iOS
问题描述
由于某些原因的fopen给出了错误没有这样的文件或目录
尽管我已经转换路径的文件路径。
For some reason fopen gives the error No such file or directory
even though I have converted the path to the documents path.
NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [docsPath stringByAppendingPathComponent:filename];
我通过使用 UTF8字符串
方法,只以阅读方式打开与
I pass the NSString using the UTF8String
method and only open in read mode with
if ((fh=fopen(filename, "r+b")) == NULL){
perror("fopen");
return -1;
}
下面的完整路径打印出来试图打开文件名时(我删除了应用的实际目录名称的确切值)
The following full path is printed out when trying to open the filename(I removed the exact values for the applications actual dir name)
在/ var /移动/应用/ ##### /文档/ testImages.pak
/var/mobile/Applications/#####/Documents/testImages.pak
为什么不FOPEN检测文件?我把它添加到目标,甚至试图改变文件检查器中的位置设置为相对于集团
和相对于项目
Why would fopen not detect the file? I have added it to the target and even tried changing the location settings in the file inspector to Relative to Group
and Relative to Project
推荐答案
您必须使用下面的方法到的NSString转换为一个char *,否则将无法正确映射到文件系统。
You have to convert the NSString to a char* using the following method, or it will not properly map to the file system.
char const *path_cstr = [fileManager fileSystemRepresentationWithPath:pathString];
现在你可以直接的fopen使用它()。
Now you can use it directly in fopen().
这篇关于iOS中的fopen问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!