Document 相关操作

//获得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;

}

时间: 2024-08-03 17:13:02

Document 相关操作的相关文章

jquery checkbox的相关操作——全选、反选、获得所有选中的checkbox

jquery checkbox的相关操作——全选.反选.获得所有选中的checkbox 1.全选 $("#btn1").click(function(){ $("input[name='checkbox']").attr("checked","true"); }) 2.取消全选(全不选) $("#btn2").click(function(){ $("input[name='checkbox']&

javascript iframe相关操作

1. 获得iframe的window对象 iframeElement.contentWindow 2. 获得iframe的document对象 存在跨域访问限制. chrome:iframeElement.contentDocument firefox:iframeElement.contentDocument ie:element.contentWindow.document 备注:ie没有iframeElement.contentDocument属性. var getIframeDocume

JS中字符串的相关操作

(转自:http://www.cnblogs.com/zhaoxinxin/articles/1402733.html) 一.字符串的创建 创建一个字符串有几种方法. 最简单的是用引号将一组字符包含起来,可以将其赋值给一个字符串变量. var myStr = "Hello, String!"; 可以用双引号或单引号将字符串包含,但要注意,作为界定字符串的一对引号必须是相同的,不能混用. 像var myString = "Fluffy is a pretty cat.'; 这样

JQuery设置checkbox选中或取消等相关操作

$("[name='checkbox']").attr("checked",'true');//全选 $("[name='checkbox']").removeAttr("checked");//取消全选 $("[name='checkbox']:even").attr("checked",'true');//选中所有奇数 //获取选择的值 var str=""; $

java 使用xom对象数据序列化为xml、反序列化、Preferences相关操作小案例

package org.rui.io.xml; import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.List; import nu.xom.Document; import nu.

web前端【第十二篇】jQuery文档相关操作

一.相关知识点总结1.CSS .css() - .css("color") -> 获取color css值 - .css("color", "#ff0000") -> 设置值 - .css({"color": "#cccccc", "border": "1px solid #ff0000"}) -> 设置多个值 - .css(["color

复选框相关操作

效果图: js代码: 第一步:请求数据 $.ajax({ type: 'get', async:false, url: "../../Ashx/GetMeeting.ashx?time="+new Date(), //data: { pageSize: Pagination.pageSize, pageIndex: Pagination.pageIndex }, success: function (result) { var data = JSON.parse(result);//e

vsto-Word相关操作

//添加页码到页脚 Document doc = Globals.ThisAddIn.Application.ActiveDocument; HeaderFooter hprimary= doc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary]; hprimary.Range.Fields.Add(hprimary.Range, WdFieldType.wdFieldPage); //添加页脚并显示页码 Document

元素的属性相关操作element.getAttribute('xxx'),element.setAttribute('xxx','xxx'),element.removeAttribute('xxx')

1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <div id="demo" class="one" title="鼠标经过">&