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

87 篇文章 0 订阅

//获取沙盒主路径

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值