繁体   English   中英

NSBundle pathForResource:返回nil

[英]NSBundle pathForResource: returns nil

我试图使用以下代码从iOS上的Xcode中的支持文件文件夹中访问.txt文件:

NSString* filePath = @"filename.txt";

NSLog(@"File path: %@", filePath);

NSString* fileRoot = [[NSBundle mainBundle] pathForResource:filePath ofType:@"txt"];

NSLog(@"File root: %@", fileRoot);

第一个NSLog打印出我希望它打印的内容,但最后一个NSLog始终只是打印

文件根:(null)

在(尝试)将文件读入内存后从文件中访问文本也简单地给了我一个(null)打印输出。

这个问题的解决方案可能就在我的鼻子底下,我似乎无法找到它。 任何帮助非常感谢! 提前致谢。

filePath已包含后缀“.txt”,因此在查找资源时不得再次指定它。

NSString* filePath = @"filename.txt";
NSString* fileRoot = [[NSBundle mainBundle] pathForResource:filePath ofType:nil];

要么

NSString* filePath = @"filename";
NSString* fileRoot = [[NSBundle mainBundle] pathForResource:filePath ofType:@"txt"];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM