iPhone:获取资源文件夹子文件夹内的文件路径 [英] iPhone : Get the file path which is within subfolder of Resource folder

查看:55
本文介绍了iPhone:获取资源文件夹子文件夹内的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

Resource文件夹结构如下:

The Resource folder structure is the following:

资源

  1. Folder1---->Data.txt
  2. Folder2---->Data.txt
  3. Folder3---->Folder1---->Data.txt

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

There are multiple files named "Data.txt", so how can I access the files in each folder? I know how to read the text file, but if the Resource structure is similar to the above structure then how can I get the path?

例如,如果我想从Folder3访问Data.txt"文件,我如何获取文件路径?

For example, if I want to access the "Data.txt" file from Folder3, how can I get the file path?

请提出建议.

推荐答案

要继续 Psychotiks 回答一个完整的例子应该是这样的:

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

}

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

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

这篇关于iPhone:获取资源文件夹子文件夹内的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆