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

IOS 开发学习十二 Bundle使用及文件引用

2015-05-14 09:24 435 查看
1.在xcode外创建一个文件夹,命令为app.bundle(必须为.bundle扩展名)

以后打开此文件夹,要鼠标右键-显示包内容,直接双击不行。

2.加到xcode项目里

3.代码获取里面文件路径:

资源路径:

NSString *bundlePath = [[NSBundle mainBundle] resourcePath];


文件路径:

NSString *url=[[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:@"app.bundle/datas.sqlite"];


上一级路径:

NSString *secondParentPath = [[bundlePath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]


不通过bundle获取资源:

UIImage *img=[UIImage imageNamed:@"cellicon.png"];


获取自定义的文件路径:

NSString *newPath=[NSString stringWithFormat:@"%@%@%@",[[NSBundle mainBundle]resourcePath],@"/",@"test.txt"];
NSFileHandle *url2=[NSFileHandle fileHandleForReadingAtPath:newPath];




NSString *newPath=[[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"];
NSFileHandle *fileHandle=[NSFileHandle fileHandleForReadingAtPath:newPath];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: