您的位置:首页 > 移动开发 > IOS开发

NSBundle

2015-10-12 10:56 351 查看
ios中去访问应用自身的资源文件可以使用NSBundle。

1.把需要访问的资源文件拖到工程中,选择复制



2、调用方式

NSBundle* bundle=[NSBundle mainBundle];
NSLog(@"%@",[bundle resourcePath]);

NSString* path= [bundle pathForResource:@"t" ofType:@"txt"] ;

NSLog(@"t.txt路径 %@",path);
NSString* txt=[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSLog(@"内容%@",txt);



打印如下
2015-10-12 10:49:50.825 core data[1116:60512] /Users/young/Library/Developer/CoreSimulator/Devices/1FA5BE80-E045-4DDE-8F79-A0257C030108/data/Containers/Bundle/Application/2EF2A37E-C5A2-4DBB-B1BD-DECBD0C562C5/core data.app
2015-10-12 10:49:50.825 core data[1116:60512] t.txt路径 /Users/young/Library/Developer/CoreSimulator/Devices/1FA5BE80-E045-4DDE-8F79-A0257C030108/data/Containers/Bundle/Application/2EF2A37E-C5A2-4DBB-B1BD-DECBD0C562C5/core data.app/t.txt
2015-10-12 10:49:50.828 core data[1116:60512] 内容abc-def- mainBundle -file
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios