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

来源:互联网 发布:淘宝新店如何推广运营 编辑:程序博客网 时间:2024/06/06 10:52

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];


0 0
原创粉丝点击