How to fopen() on the iPhone?

前端 未结 2 1314
甜味超标
甜味超标 2020-12-13 20:42

The iPhone SDK docs claim fopen() is a supported method of file access but I am unable to get it to return a FILE handle. I am accessing a directory which is included in my

相关标签:
2条回答
  • 2020-12-13 21:25

    if you're trying to access a file within your application bundle, you need to get the full path to it: [[NSBundle mainBundle] pathForResource: FILENAME ofType: FILEEXTENSION]

    This returns an NSString, which you can pull a UTF8String out of and pass to fopen.

    0 讨论(0)
  • 2020-12-13 21:29

    Just to be clear to open a file "some.txt"...

    NSString * path = [[NSBundle mainBundle] pathForResource:  @"some" ofType: @"txt"];
    FILE *f = fopen([path cStringUsingEncoding:1],"r");
    if (f == NULL) NSLog([path stringByAppendingString:@" not found"]);
    
    0 讨论(0)
提交回复
热议问题