iOS 沙盒文件操作
//获得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 沙盒文件操作的更多相关文章
- IOS应用沙盒文件操作
iOS沙盒机制 iOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都要保存在此,例如图像,图标,声音,映像,属性列表,文本文件等. 1 ...
- 使用libimobiledevice + ifuse提取iOS沙盒文件
简介 libimobiledevice:一个开源包,可以让Linux支持连接iPhone/iPod Touch等iOS设备. Git仓库: https://github.com/libimobiled ...
- iOS_SN_沙盒文件操作及位置
转载:http://blog.csdn.net/hello_hwc/article/details/44916909 沙盒的结构如下所示 一 访问Bundle 注意Bundle只读,不能写入 创建一个 ...
- iOS 沙盒路径操作:新建/删除文件和文件夹
http://blog.csdn.net/totogo2010/article/details/7671144
- iOS关于沙盒文件拷贝manager.copyItem的一个坑
记录一下: 沙盒文件操作,当需要拷贝文件时,我们可以使用如下类似方式: // 文件拷贝 func copyFile(from:String,to:String)->Bool{ if !manag ...
- IOS 学习之 iOS沙盒(sandbox) 介绍 沙盒机制 文件操作(一)
1.iOS沙盒机制 iOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都要保存在此,例如图像,图标,声音,映像,属性列表,文本文件等. ...
- iOS 沙盒(sandbox)机制和文件操作
本文参看了 http://www.uml.org.cn/mobiledev/201209211.asp#1 这篇文章中的介绍,尊重原著. 1.IOS沙盒机制 IOS应用程序只能在本应用程序中创建的文件 ...
- IOS学习之IOS沙盒(sandbox)机制和文件操作
IOS学习之IOS沙盒(sandbox)机制和文件操作(一) 1.IOS沙盒机制 IOS应用程序只能在为该改程序创建的文件系统中读取文件,不可以去其它地方访问,此区域被成为沙盒,所以所有的非代码文件都 ...
- iOS学习之iOS沙盒(sandbox)机制和文件操作(一)
1.iOS沙盒机制 iOS应用程序仅仅能在为该改程序创建的文件系统中读取文件,不能够去其他地方訪问,此区域被成为沙盒,所以全部的非代码文件都要保存在此,比如图像,图标,声音,映像,属性列表,文本文件等 ...
随机推荐
- image的resizeMode属性
Image组件必须在样式中声明图片的宽和高.如果没有声明,则图片将不会被呈现在界面上. 我们一般将Image定义的宽和高乘以当前运行环境的像素密度称为Image的实际宽高. 当Image的实际宽 ...
- 下划线hover下动态出现技巧
酷炫的动画效果往往更能吸引眼球,下面我将分享纯CSS中,hover的时候出现下划线动态飞入的技巧. 1.下划线从左侧飞入: div::before{ content:""; wid ...
- Css选择器和JQuery基本编程接口
使用JQuery之前,首先从官网下载库文件 http://jquery.com/ jquery-2.1.4.js和jquery-2.1.4.min.js,前者是完整无压缩版本,用于开发调试:后者是压缩 ...
- redhat 7.x 、redhat 6.x查看硬盘UUID方法
1.查看磁盘分区UUID: [root@rac01 ~]# blkid /dev/sdb1: UUID="6bba92c4-0b25-4cc4-9442-ca87c563720a" ...
- IDM下载器使用方法详解:百度网盘下载,视频会员一网打尽!
一. IDM的设置 [01]IDM插件与各大浏览器的集成 默认情况下,在成功安装IDM后,直接点击这里的选项,会弹出[常规设置],一般情况下直接保持默认的配置即可,如果你使用的是比较小众的浏览器,你可 ...
- 一直被用错的6种SQL 错误用法
一直被用错的6种SQL 错误用法 1.LIMIT 语句 2.隐式转换 3.关联更新.删除 4.EXISTS语句 5.条件下推 6.提前缩小范围 sql语句的执行顺序: FROM ON JOIN WHE ...
- IDEA中远程Debug调试
一.设置JVM支持远程Debug调式 由于我的应用是springboot, 所以直接使用java -jar的方法将服务启动起来. java -Xdebug -Xrunjdwp:transport=dt ...
- AutoItLibrary之键盘操作(send)
最近有人问到我键盘操作用什么库?用到库里面的哪个方法?我在这里总结一下,第一次写,有片面的地方还请指出,一块进步.1.首先,用到的库是AutoItLibrary,用到的方法是send:按F5可用看到 ...
- 软件测试人员遇到发现的bug不能重现怎么办?
软件测试人员遇到发现的bug不能重现怎么办? 刚刚进入测试的童鞋们,想必都遇到过提出的bug,开发要求重现之后,但是在系统上已经重现不了的情况吧. 那么碰到这样的情况,不管开发还是测试都很纠结,开 ...
- FZU1004-Number Triangle经典动归题,核心思路及代码优化
Problem 1004 Number Triangle Accept: 2230 Submit: 5895Time Limit: 1000 mSec Memory Limit : 327 ...