• iOS沙盒


    iOS沙盒中一共有四个文件夹 

    ------安装目录(r)

          -------Ducuments:长期存放用户文件或文件夹(rw)

          -------A.pp:mainBundle:存放可执行文件和资源文件(r)

          -------tmp:存放临时文件(r,w) 

          -------Library 

             -------caches:存放缓存文件(rw)

    访问这些文件的方法:

    //获取根目录路径

        NSString *home=NSHomeDirectory();

        NSLog(@"%@",home);//打印出该路径

        //第一种:获取出Documents的路径的方法:字符串形式打印(再有根目录的路径为前     提)

        NSString *doc=[home stringByAppendingPathComponent:@"Documents"];

        NSLog(@"%@",doc);

      

          //第二种:获取出Documents的路径的方法:数组形式

     NSArray *path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

        NSLog(@"%@ ",path);

        //将Documents路径由数组形式变为字符串形式。

        NSString *path2=[path objectAtIndex:0];

        NSLog(@"%@",path2); 

       //获取出caches的路径 数组形式

    NSArray *pathc=NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);

        NSLog(@"%@",pathcaches);

        //将caches路径由数组形式变为字符串形式。

        NSString *pathc2=[pathc objectAtIndex:0];

        NSLog(@" ::: %@  ",path3);

        

       //获取出tmp的路径

        NSString *pathtmp=NSTemporaryDirectory();

        NSLog(@"%@",pathtmp);

         //获取app中的testDab.bd文件的路径

        NSString *dbPath = [[NSBundle mainBundle]   pathForResource:@"testDaB" ofType:@"db"];

        NSLog(@"%@", dbPath);


         //将name这个字符串  写入到path0指定的文件中去。

        [name writeToFile:path0 atomically:YES encoding:NSUTF8StringEncoding error:nil];

  • 相关阅读:
    状压DP之排列perm
    CodeForces 578F Mirror Box
    Berlekamp-Massey算法
    图解git操作
    yapi安装
    springcloud gateway
    springcloud alibaba
    反射和内置方法
    绑定方法与非绑定方法
    多态性和鸭子类型
  • 原文地址:https://www.cnblogs.com/lucan727/p/3883680.html
Copyright © 2020-2023  润新知