//获得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. 2018 CCPC 女生赛 hdoj6288 缺失的数据范围

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6288 Summarize:1.二分查找答案: 2.自带log函数精度不够,需自己写: 3.注意二分递归 ...

  2. SDOI2011 拦截导弹

    题目描述 题解: 对于第一问,我们求二维LIS即可; 对于第二问,我们可以记录向前最长长度,向前最长方案数,向后最长长度,向后最长方案数. 其实改改树状数组即可. 还有,方案数一定要开double. ...

  3. Centos 7 编译php 7.2.10

    步骤一:安装依赖 yum install -y wget gcc gcc-c++ gd-devel zlib-devel libjpeg-devel libpng-devel libiconv-dev ...

  4. Centos7 使用firewall管理防火墙

    一.Centos7使用firewall的管理防火墙 1.firewalld基本使用 启动:systemctl start firewalld 关闭:systemctl stop firewalld 状 ...

  5. vue App.vue router 过渡效果, keep-alive 结合使用示例

    1, router.js配置 每个路由的index值 2, router.js配置 每个路由的keepAlive值 app.vue 代码 <template> <div id=&qu ...

  6. 基于selenium爬取拉勾网职位信息

    1.selenium Selenium 本是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.而这一特性为爬虫开发提供了一个选择及方向,由于其本身依赖 ...

  7. luogu2596 [ZJOI2006]书架

    treap.树是以"优先级"(优先级越小,在书架上越靠上)形成的,堆是以rand()的权值形成的.还要再维护一个原编号. 置顶/置底:找到那个元素,把它拉出来修改优先级再塞回去. ...

  8. FZU2206函数求解

    Problem 2206 函数求解 Accept: 154    Submit: 456 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Probl ...

  9. BZOJ 3039: 玉蟾宫【dp】

    Description 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地.这片土地被分成N*M个格子,每个格子里写着'R'或者' ...

  10. BZOJ3027 - [CEOI2004]Sweet

    Portal Description 给出\(n(n\leq10),a,b(a,b\leq10^7)\)与\(\{c_n\}(c_i\leq10^6)\),求使得\(\sum_{i=1}^n x_i ...