//获得document

+(NSString *)documentsPath {

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

return [paths objectAtIndex:0];

}

//读取工程文件

+(NSString *) ProductPath:(NSString*)filename{

NSString *path = [[NSBundlemainBundle] pathForResource:filename ofType:@""];

return  path;

}

//获得document文件路径,名字方便记忆

+(NSString *) DocumentPath:(NSString *)filename {

NSString *documentsPath = [self documentsPath];

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

return [documentsPath stringByAppendingPathComponent:filename];

}

//获得document文件路径

+(NSString *)fullpathOfFilename:(NSString *)filename {

NSString *documentsPath = [self documentsPath];

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

return [documentsPath stringByAppendingPathComponent:filename];

}

//写入文件沙盒位置NSDictionary

+(void)saveNSDictionaryForDocument:(NSDictionary *)list  FileUrl:(NSString*) FileUrl  {

NSString *f = [self fullpathOfFilename:FileUrl];

[list writeToFile:f atomically:YES];

}

//写入文件存放到工程位置NSDictionary

+(void)saveNSDictionaryForProduct:(NSDictionary *)list  FileUrl:(NSString*) FileUrl  {

NSString *ProductPath =[[NSBundlemainBundle]  resourcePath];

NSString *f=[ProductPath stringByAppendingPathComponent:FileUrl];

[list writeToFile:f atomically:YES];

}

//写入文件 Array 工程

+(void)saveOrderArrayListProduct:(NSMutableArray *)list  FileUrl :(NSString*) FileUrl {

NSString *ProductPath =[[NSBundlemainBundle]  resourcePath];

NSString *f=[ProductPath stringByAppendingPathComponent:FileUrl];

[list writeToFile:f atomically:YES];

}

//写入文件 Array 沙盒

+(void)saveOrderArrayList:(NSMutableArray *)list  FileUrl :(NSString*) FileUrl {

NSString *f = [self fullpathOfFilename:FileUrl];

[list writeToFile:f atomically:YES];

}

//加载文件沙盒NSDictionary

+(NSDictionary *)loadNSDictionaryForDocument  : (NSString*) FileUrl {

NSString *f = [self fullpathOfFilename:FileUrl];

NSDictionary *list = [ [NSDictionaryalloc] initWithContentsOfFile:f];

return [list autorelease];

}

//加载文件工程位置NSDictionary

+(NSDictionary *)loadNSDictionaryForProduct   : (NSString*) FileUrl {

NSString *f = [self ProductPath:FileUrl];

NSDictionary *list =[NSDictionarydictionaryWithContentsOfFile:f];

return list;

}

//加载文件沙盒NSArray

+(NSArray *)loadArrayList   : (NSString*) FileUrl {

NSString *f = [self fullpathOfFilename:FileUrl];

NSArray *list = [NSArray  arrayWithContentsOfFile:f];

return list;

}

//加载文件工程位置NSArray

+(NSArray *)loadArrayListProduct   : (NSString*) FileUrl {

NSString *f = [self ProductPath:FileUrl];

NSArray *list = [NSArray  arrayWithContentsOfFile:f];

return list;

}

//拷贝文件到沙盒

+(int) CopyFileToDocument:(NSString*)FileName{

NSString *appFileName =[self fullpathOfFilename:FileName];

NSFileManager *fm = [NSFileManagerdefaultManager];

//判断沙盒下是否存在

BOOL isExist = [fm fileExistsAtPath:appFileName];

if (!isExist)   //不存在,把工程的文件复制document目录下

{

//获取工程中文件

NSString *backupDbPath = [[NSBundle mainBundle]

pathForResource:FileName

ofType:@""];

//这一步实现数据库的添加,

// 通过NSFileManager 对象的复制属性,把工程中数据库的路径复制到应用程序的路径上

BOOL cp = [fm copyItemAtPath:backupDbPath toPath:appFileName error:nil];

return cp;

} else {

return  -1; //已经存在

}

}

//判断文件是否存在

+(BOOL) FileIsExists:(NSString*) checkFile{

if([[NSFileManagerdefaultManager]fileExistsAtPath:checkFile])

{

return true;

}

return  false;

}

iOS 沙盒文件操作的更多相关文章

  1. IOS应用沙盒文件操作

    iOS沙盒机制 iOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都要保存在此,例如图像,图标,声音,映像,属性列表,文本文件等. 1 ...

  2. 使用libimobiledevice + ifuse提取iOS沙盒文件

    简介 libimobiledevice:一个开源包,可以让Linux支持连接iPhone/iPod Touch等iOS设备. Git仓库: https://github.com/libimobiled ...

  3. iOS_SN_沙盒文件操作及位置

    转载:http://blog.csdn.net/hello_hwc/article/details/44916909 沙盒的结构如下所示 一 访问Bundle 注意Bundle只读,不能写入 创建一个 ...

  4. iOS 沙盒路径操作:新建/删除文件和文件夹

    http://blog.csdn.net/totogo2010/article/details/7671144

  5. iOS关于沙盒文件拷贝manager.copyItem的一个坑

    记录一下: 沙盒文件操作,当需要拷贝文件时,我们可以使用如下类似方式: // 文件拷贝 func copyFile(from:String,to:String)->Bool{ if !manag ...

  6. IOS 学习之 iOS沙盒(sandbox) 介绍 沙盒机制 文件操作(一)

    1.iOS沙盒机制 iOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都要保存在此,例如图像,图标,声音,映像,属性列表,文本文件等. ...

  7. iOS 沙盒(sandbox)机制和文件操作

    本文参看了 http://www.uml.org.cn/mobiledev/201209211.asp#1 这篇文章中的介绍,尊重原著. 1.IOS沙盒机制 IOS应用程序只能在本应用程序中创建的文件 ...

  8. IOS学习之IOS沙盒(sandbox)机制和文件操作

    IOS学习之IOS沙盒(sandbox)机制和文件操作(一) 1.IOS沙盒机制 IOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都 ...

  9. iOS学习之iOS沙盒(sandbox)机制和文件操作(一)

    1.iOS沙盒机制 iOS应用程序仅仅能在为该改程序创建的文件系统中读取文件,不能够去其他地方訪问,此区域被成为沙盒,所以全部的非代码文件都要保存在此,比如图像,图标,声音,映像,属性列表,文本文件等 ...

随机推荐

  1. 核心动画中的几种layer

    第10章其他有用的层 免责申明(必读!):本博客提供的所有教程的翻译原稿均来自于互联网,仅供学习交流之用,切勿进行商业传播.同时,转载时不要移除本申明.如产生任何纠纷,均与本博客所有人.发表该翻译稿之 ...

  2. 遇到的django问题

    问题1: No migrations to apply 删除了migrations中0001_initial.py文件,重新执行 python manage.py makemigrations pyt ...

  3. ES搭建

    https://www.cnblogs.com/jstarseven/p/6803054.html

  4. Oracle 11G RAC For ASM 利用RMAN COPY进行存储迁移

    转载请注明出处 一.需求背景 客户数据库存储空间接近存满,需购置一台新的存储,进行数据迁移,客户允许少量停机时间. 二.实施方法讨论 利用ASM rebalance 进行迁移 可以实现0宕机进行迁移, ...

  5. js事件默认行为

    事件默认行为: 当一个事件发生的时候浏览器自己默认做的事情 怎么阻止? 当前这个行为是什么事件触发的,然后在这个事件的处理函数中使用 return false; 但是return false 阻止的是 ...

  6. 第五讲:Fast RTL-level verification

    1.good code styles 2.+rad compile time switch  for compile 1.了解VCS 的架构  <===这方便了解不多 parser / even ...

  7. jquery 打星评分插件

    <link rel="stylesheet" href="/static/vendor/raty/jquery.raty.css"> <scr ...

  8. Spring Boot 返回Html界面

    @Controller public class HelloController { @RequestMapping("/") public String index(){ ret ...

  9. Vue如何在webpack设置代理解决跨域问题

            在开发过程中我们请求数据有时候调用的是第三方接口,此时便会遇到一个问题:跨域限制.对于跨域问题的解释就不详细叙述了,要了解的请自行百度.一般跨域问题控制台会报这个错:         ...

  10. CU论坛常用知识点汇总

    1.正则表达式详解 http://bbs.chinaunix.net/thread-63273-1-1.html http://bbs.chinaunix.net/thread-605570-1-1. ...