iOS 通过路径对文件写入数据 读取数据
来源:互联网 发布:c语言创建多个进程 编辑:程序博客网 时间:2024/05/17 09:02
1获取沙盒不同文件的路径、
-(void)getFilePath{
// 1、获取程序的Home目录
NSString *path =NSHomeDirectory();
NSLog(@"这是home目录%@",path);
// 2、获取Document目录
NSArray *documentpaths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSLog(@"%@",documentpaths);
NSString *documentpath = [documentpathsobjectAtIndex:0];
NSLog(@"这是Docuemt目录%@",documentpath);
// 3、获取Cache目录
NSArray *cachePath =NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES);
NSString *cachePaths = [cachePathobjectAtIndex:0];
NSLog(@"这是Cache目录%@",cachePaths);
// 4、获取Library目录
NSArray *tempPath =NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask, YES);
NSString *tempPaths = [tempPathobjectAtIndex:0];
NSLog(@"这是Librayr目录%@",tempPaths);
// 5、获取Tmp目录
NSString *tempDirectory =NSTemporaryDirectory();
NSLog(@"这是temp目录%@",tempDirectory);
}
-(void)writeFileContent{
// 将内容写入文件
NSArray *path =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *paths = [pathobjectAtIndex:0];
// NSArray *array = [[NSArray alloc]initWithObjects:@"内容",@"content", nil];
NSArray *array =@[@"abc",@"def",@"ggg",@10];
NSString *filepath = [pathsstringByAppendingPathComponent:@"textFile.text"];
[array writeToFile:filepathatomically:YES];
}
-(void)readFile{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *docDir = [pathsobjectAtIndex:0];
NSString *filePath1 = [docDirstringByAppendingPathComponent:@"textFile.text"];
NSArray *array = [[NSArrayalloc] initWithContentsOfFile:filePath1];
NSLog(@"%@",array);
}
- iOS 通过路径对文件写入数据 读取数据
- 一种对文件读取和写入数据的方法
- iOS中plist,数据写入与读取
- 通过读取串口数据,把数据写入MySQL
- 由文件的路径,写入数据
- C# xml文件读取节点写入数据
- 文件创建 数据写入 读取 删除
- matlab写入和读取文件数据
- 使用PHPExcel读取写入Excel文件数据
- java通过相对路径读取properties数据
- java代码--通过某路径读取数据
- qt数据写入文件和读取文件里的数据
- ios开发系列之文件的写入读取,NSUserDefaults存储数据,NSFileManager操作文件和文件夹
- 如何创建内存映射文件,并对其进行写入与读取数据
- 读取写入SharedPreferences数据
- 数据写入读取
- iOS文件写入读取
- java将数据写入xml与读取xml文件数据
- android项目工程下各文件夹的含义
- 118. Pascal's Triangle
- 将JNI模块打包为AAR模块
- Python中的lambda和Map混合运用
- servlet之qq(二)
- iOS 通过路径对文件写入数据 读取数据
- linux环境变量设置
- Ajax_数据格式_JSON(03)
- win10下面部署Mysql数据库
- 参数估计方法
- dex文件的反编译-dex2jar和jd-gui
- android的广播发送与接收
- java directmemory监控
- neural-networks-and-deep-learning misleading_gradient_contours.py