NSBundle

来源:互联网 发布:wz111和59数据对比 编辑:程序博客网 时间:2024/06/05 14:53

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.app2015-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.txt2015-10-12 10:49:50.828 core data[1116:60512] 内容abc-def- mainBundle -file



0 0
原创粉丝点击