获取 沙盒主路径 及其他下面的文件路径
2015-09-28 20:20
405 查看
//获取沙盒主路径
NSString *homePath =
NSHomeDirectory();
NSLog(@"homePath:%@",homePath);
//获取document路径
//返回是一个数组,iOS端只有一个document,为什么返回的是数组呢,是因为Mac端和iOS端都是用同一门语言,在Mac端是可以有多个document的,所以返回的是数组。
//第一个参数表示的是一个路径
//第二个参数表示的是是主人用户还是客人用户,在iOS端也是只有一个用户
//NSSearchPathForDirectoriesInDomains(<#NSSearchPathDirectory directory#>, <#NSSearchPathDomainMask domainMask#>, <#BOOL expandTilde#>)
//第三个参数:YES
显示完整路径, NO 显示相对路径
//document:通常用来存放应用程序需要持久化使用的关键数据,比如本地数据库等。
//iTunes在备份的时候会自动备份此文件夹。
NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, NO)
objectAtIndex:0];
NSLog(@"document:%@",documentPath);
//libray:通常用来存储应用程序运行期间生成的持久化数据,比如用户账户名等。应用程序退出后不会被删除文件夹内数据,
//但是iTunes备份时不会备份此文件夹。
NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, NO)
objectAtIndex:0];
NSLog(@"library:%@",libraryPath);
//cache:运行期间的缓存文件、历史记录等。
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
NSUserDomainMask, NO)
objectAtIndex:0];
NSLog(@"cache:%@",cachePath);
//preferences:应用程序的设置,比如夜间模式等。
//tmp:存放临时文件,应用程序结束后清除。
NSString *tmpPath =
NSTemporaryDirectory();
NSLog(@"tmp%@",tmpPath);
#pragma mark Bundle
//获取当前应用程序
NSBundle *bundle = [NSBundle
mainBundle];
//获取当前包得路径
NSString *bundlePath = [bundle
resourcePath];
NSLog(@"bundlePath:%@",bundlePath);
//或者
NSString *bundlePathA = [bundle
bundlePath];
NSLog(@"bundlePathA:%@",bundlePathA);
//资源路径:图片路径
NSString *imagePath = [bundle
pathForResource:@"background@2x"
ofType:@"png"];
NSLog(@"imagePath:%@",imagePath);
//
NSString *interfacePath = [bundle
pathForResource:@"News"
ofType:@"txt"];
NSLog(@"interfacePath:%@",interfacePath);
NSString *homePath =
NSHomeDirectory();
NSLog(@"homePath:%@",homePath);
//获取document路径
//返回是一个数组,iOS端只有一个document,为什么返回的是数组呢,是因为Mac端和iOS端都是用同一门语言,在Mac端是可以有多个document的,所以返回的是数组。
//第一个参数表示的是一个路径
//第二个参数表示的是是主人用户还是客人用户,在iOS端也是只有一个用户
//NSSearchPathForDirectoriesInDomains(<#NSSearchPathDirectory directory#>, <#NSSearchPathDomainMask domainMask#>, <#BOOL expandTilde#>)
//第三个参数:YES
显示完整路径, NO 显示相对路径
//document:通常用来存放应用程序需要持久化使用的关键数据,比如本地数据库等。
//iTunes在备份的时候会自动备份此文件夹。
NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, NO)
objectAtIndex:0];
NSLog(@"document:%@",documentPath);
//libray:通常用来存储应用程序运行期间生成的持久化数据,比如用户账户名等。应用程序退出后不会被删除文件夹内数据,
//但是iTunes备份时不会备份此文件夹。
NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, NO)
objectAtIndex:0];
NSLog(@"library:%@",libraryPath);
//cache:运行期间的缓存文件、历史记录等。
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
NSUserDomainMask, NO)
objectAtIndex:0];
NSLog(@"cache:%@",cachePath);
//preferences:应用程序的设置,比如夜间模式等。
//tmp:存放临时文件,应用程序结束后清除。
NSString *tmpPath =
NSTemporaryDirectory();
NSLog(@"tmp%@",tmpPath);
#pragma mark Bundle
//获取当前应用程序
NSBundle *bundle = [NSBundle
mainBundle];
//获取当前包得路径
NSString *bundlePath = [bundle
resourcePath];
NSLog(@"bundlePath:%@",bundlePath);
//或者
NSString *bundlePathA = [bundle
bundlePath];
NSLog(@"bundlePathA:%@",bundlePathA);
//资源路径:图片路径
NSString *imagePath = [bundle
pathForResource:@"background@2x"
ofType:@"png"];
NSLog(@"imagePath:%@",imagePath);
//
NSString *interfacePath = [bundle
pathForResource:@"News"
ofType:@"txt"];
NSLog(@"interfacePath:%@",interfacePath);
相关文章推荐
- java基础之集合List、Set、Map的区别
- iOS界面编程-UILabel
- http://kb.cnblogs.com/page/196448/
- MySQL学习笔记之视图
- 19、linux软件管理之简述
- java 时间转换 将 util 时间转成 sql 时间
- Cannot read property 'root' of null 解决方法
- 跑马
- JAVA对文件的读操作总结
- 使用StatFs用于获取系统/sdcard存储空间信息 api18中增加的方法
- HDU 5475 An easy problem
- 水
- linux定时任务的设置
- Android内存优化之OOM
- HBase1.1.2编译
- 2015第40周一Node学习
- 使用xml.etree.ElementTree读xml
- 模糊查找
- http://www.guokr.com/blog/475765/
- Session 失效原因