码迷,mamicode.com
首页 > 移动开发 > 详细

iOS沙盒

时间:2014-07-31 23:45:20      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:os   io   文件   for   ar   htm   type   res   

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(@"%@\n",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];

 

iOS沙盒,布布扣,bubuko.com

iOS沙盒

标签:os   io   文件   for   ar   htm   type   res   

原文地址:http://www.cnblogs.com/lucan727/p/3883680.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!