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应用程序仅仅能在为该改程序创建的文件系统中读取文件,不能够去其他地方訪问,此区域被成为沙盒,所以全部的非代码文件都要保存在此,比如图像,图标,声音,映像,属性列表,文本文件等 ...
随机推荐
- C# 关于datetime的用法(网上考的)
实例: 用户输入一个日期,要求输出这个日期是星期几和在这一年中的第几天: 复制代码代码如下: //声明一个DateTime类型的变量用于存放用户输入的日期DateTime dt;Console.Wri ...
- xenserver tools 安装
mkdir -p /mnt/xtools mount /dev/cdrom /mnt/xtools cd /mnt/xtools/Linux/ ./install.sh -n init 6
- spring-mvc junit测试
import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; impor ...
- configparser ,subprocess , xlrd ,xlwt 模块
一,configparser模块 ''' configparser模块: 是什么: 用于解析配置文件的模块 配置文件的定义: 用于编写保存某个软件或某个系统的一系列参数的文件 设置参数 为什么需要配置 ...
- crm 简约笔记
crm# 给modelform使用的 tutor = models.ForeignKey(verbose_name='班主任', to='UserInfo', related_name='cla ...
- 剑指Offer(书):剪绳子
题目:给你一根长度为n的绳子,请把绳子剪成m段,每段绳子的长度记为k[0],k[1]....,k[m].请问k[0]xk[1]x...,k[m]可能的最大乘积是多少.例如:长度为8剪成2 3 3 得到 ...
- LeetCode(77) Combinations
题目 Given two integers n and k, return all possible combinations of k numbers out of 1 - n. For examp ...
- LeetCode(237)Delete Node in a Linked List
题目 Write a function to delete a node (except the tail) in a singly linked list, given only access to ...
- FZU2102Solve equation
Problem 2102 Solve equation Accept: 881 Submit: 2065 Time Limit: 1000 mSec Memory Limit : 3276 ...
- POJ 1236 学校网络间的强连通
题目大意: N个学校之间有单向的网络,每个学校得到一套软件后,可以通过单向网络向周边的学校传输.问题1:初始至少需要向多少个学校发放软件,使得网络内所有的学校最终都能得到软件.问题2:至少需要添加几条 ...