ios – iPhone:获取Resource文件夹子文件夹中的文件路径

我是iPhone编程的新手.我想读取位于资源文件夹子文件夹中的文本文件内容.

资源文件夹结构如下:

资源

> Folder1 —-> Data.txt
> Folder2 —-> Data.txt
> Folder3 —-> Folder1 —-> Data.txt

有多个名为“Data.txt”的文件,那么如何访问每个文件夹中的文件?我知道如何读取文本文件,但如果资源结构类似于上述结构,那么如何获取路径?

例如,如果我要从Folder3访问“Data.txt”文件,我该如何获取文件路径?

请建议.

解决方法

继续精神病患者回答一个完整的例子将如下所示:
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

}

请注意,您可以使用-pathForResource:ofType:inDirectory来访问子目录中的资源.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...