iPhone - fopen 和 pathForResource - 权限被拒绝
我尝试直接打开文件,例如 fopen("/test.txt","w+")
; 它可以在模拟器上运行,但不能在 iPhone 上运行。
然后我尝试了这个:
NSString *path = [[NSBundle mainBundle] pathForResource: @"GirlName.txt" ofType:nil];
NSLog(path);
fichier = fopen([path cStringUsingEncoding:1],"w+");
if (fichier != NULL)
{
...
}
else
{
perror("error ");
}
我在控制台中收到权限被拒绝:
2009-07-24 17:17:27.415 Mademoiselle[897:20b]
/var/mobile/Applications/.../....app/GirlName.txt
error : Permission denied
你能告诉我出了什么问题吗?
I've tried to open a file directly like fopen("/test.txt","w+")
; it works on the simulator but doesn't work on the iPhone.
Then I've tried this:
NSString *path = [[NSBundle mainBundle] pathForResource: @"GirlName.txt" ofType:nil];
NSLog(path);
fichier = fopen([path cStringUsingEncoding:1],"w+");
if (fichier != NULL)
{
...
}
else
{
perror("error ");
}
I receive in console Permission denied:
2009-07-24 17:17:27.415 Mademoiselle[897:20b]
/var/mobile/Applications/.../....app/GirlName.txt
error : Permission denied
Can you tell me what's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法打开应用程序包中的文件并使其可写(“w+”)。
如果您将模式更改为“r”,则相同的代码可能会起作用(我还没有测试过)
如果您需要一个可写文本文件,则需要将其放在可写目录中,我会执行以下操作:
You cannot open a file within the application bundle and make it writable ("w+").
This same code will likely work (I have not tested it) if you change the mode to "r"
If you need a writable text file, you need to place in in a writable directory, I'd do something like this: