您的位置:首页 > 其它

获取 沙盒主路径 及其他下面的文件路径

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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: