IOS文件系统

IOS文件系统

当开发者第一次启动app时,IOS操作系统就为此app创建了一个文件系统,该文件系统下默认有四个,分别是:
Documents:存储用户在操作app时产生的数据,使目录下的数据可以通过iCloud进行同步。
Library:用户偏好设置数据,通常和此类NSUserDefaults搭配使用,此目录下的数据可以通过iCloud进行同步。
Tmp:存在临时数据,此目录下的数据不会通过iCloud进行同步。

Ipa包:开发者不会操作此目录,通常是通过此类NSBundle类。

 //获取程序根目录

    NSString *homePath = NSHomeDirectory();
    //获取根目录下的Documents目录
    NSString *documentsPath = [homePath stringByAppendingPathComponent:@"Documents"];

    //或者
    documentsPath = [homePath stringByAppendingFormat:@"/Documents"];
//最常用的获取Documents目录
    documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    NSLog(@"documentPath = %@",documentsPath);

//字符串拼接
NSString *libraryPath = [homePath stringByAppendingString:@”Documents”];
//C函数获取Library目录
libraryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) objectAtIndex:0];

libraryPath = [homePath stringByAppendingString:@"/library"];
NSLog(@"libraryPath = %@",libraryPath);

//获取tmp目录
NSString *tmpPath = NSTemporaryDirectory();
    //app包,获取包内的图片,显示在UI上
    NSBundle *bundle = [NSBundle mainBundle];
    NSLog(@"bundlePath = %@",bundle.bundlePath);
    NSString *imgPath = [bundle pathForResource:@"5.pic" ofType:@"jpg"];
    NSData *imgData = [NSData dataWithContentsOfFile:imgPath];
    UIImage *image = [UIImage imageWithData:imgData];
    self.imageView.image = image;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值