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