iPhone : Get the file path which is within subfolder of Resource folder

后端 未结 4 417
死守一世寂寞
死守一世寂寞 2020-12-09 12:24

I am new to iPhone programming. I want to read the content of a text file located in a subfolder of the Resource folder.

The Resource folder structure is the followi

4条回答
  •  时光说笑
    2020-12-09 12:59

    To continue psychotiks answer a full example would look like this:

    NSBundle *thisBundle = [NSBundle bundleForClass:[self class]];
    NSString *filePath = nil;
    
    if (filePath = [thisBundle pathForResource:@"Data" ofType:@"txt" inDirectory:@"Folder1"])  {
    
        theContents = [[NSString alloc] initWithContentsOfFile:filePath];
    
        // when completed, it is the developer's responsibility to release theContents
    
    }
    

    Notice that you can use -pathForResource:ofType:inDirectory to access ressources in sub directories.

提交回复
热议问题