//获得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. eclipse修改SVN账号密码

    首先,eclipse中打开window------>preferences------->SVN页面,如下所示: 注意我圈起来的地方,JavaHL是不可用的,因此SVN接口应该是SVNKi ...

  2. iOS之绘制像素到屏幕

    译注:这篇文章虽然比较长,但是里面的内容还是很有价值的. 像素是如何绘制到屏幕上面的?把数据输出到屏幕的方法有很多,通过调用很多不同的framework和不同的函数.这里我们讲一下这个过程背后的东西. ...

  3. ios之UITextfield (2)

    UItextField通常用于外部数据输入,以实现人机交互.下面以一个简单的登陆界面来讲解UItextField的详细使用. //用来显示“用户名”的label UILabel* label1 = [ ...

  4. contextify::ContextifyScript::New(const v8::FunctionCallbackInfo<v8::Value>&):

    问题描述 在执行grunt 命令时候报错 contextify::ContextifyScript::New(const FunctionCallbackInfo<v8::Value> & ...

  5. 分享一款非常好用的Fatkun图片批量下载工具

    Fatkun图片批量下载 相信大家一定遇到过有着大量精美图片的网页,譬如美女照片.各种壁纸.设计素材.甚至是1024套图等等,但常常几十上百张的图要一张张手工去点击下载实在能让人抓狂!小编的工作中也常 ...

  6. Python之队列

    Python之队列 队列:先进先出 队列与线程有关. 在多线程编程时,会起到作用. 作用:确保信息安全的进行交换. 有get 和 put 方法. ''' 创建一个“队列”对象 import Queue ...

  7. Python 3.52官方文档翻译 http://usyiyi.cn/translate/python_352/library/index.html 必看!

    Python 3.52官方文档翻译   http://usyiyi.cn/translate/python_352/library/index.html 觉得好的麻烦点下推荐!谢谢!

  8. 安装完Centos 7后的一些处理

    1.安装dkms:dkms-2.2.0.3-31.1.noarch.rpm 2.安装显卡驱动:amdgpu-pro-18.10-572953 3.启动图形界面使用init 5 不能使用startx

  9. 杭电 4707 pet(并查集求元素大于k的集合)

    Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searche ...

  10. 2017acm南宁现场赛 J题 Rearrangement

    题意: 给定一个2 * n的矩阵, 和 2 * n 个数, 问能不能通过重排列, 使得任意相邻两数不能被3整除 分析: 这题一直卡到最后, 赛后经对面大佬提醒后, 发现统计所有数模三的结果(0,1,2 ...