iphone创建文件
来源:互联网 发布:国外用淘宝吗 编辑:程序博客网 时间:2024/06/06 12:47
注意2点:
1、创建多级目录的文件时,要先判断其目录是否存在,如果不存在就创建该目录,如果没有创建该目录,文件是不能创建成功的
2、不要使用
- (BOOL)createDirectoryAtPath:(NSString *)path attributes:(NSDictionary *)attributes,这个方法在模拟器中可能能成功运行,但在设备上肯定不行的,改用- (BOOL)createDirectoryAtPath:(NSString *)path withIntermediateDirectories:(BOOL)createIntermediates attributes:(NSDictionary *)attributes error:(NSError **)error,
记得将createIntermediates设置为YES,这样就能建立多级目录了。如果是一级目录,可以设置为NO。
demo如下:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *strFile = [documentsDirectory stringByAppendingPathComponent:@"hello/config.plist"]; NSLog(@"strFile: %@", strFile); NSString *strPath = [documentsDirectory stringByAppendingPathComponent:@"hello"]; if (![[NSFileManager defaultManager] fileExistsAtPath:strPath]) { NSLog(@"there is no Directory: %@",strPath); [[NSFileManager defaultManager] createDirectoryAtPath:strPath withIntermediateDirectories:YES attributes:nil error:nil]; } NSArray *keys = [NSArray arrayWithObjects: @"username", @"password", @"serverName", @"serverPort", @"autoSave", nil]; NSArray *values = [NSArray arrayWithObjects: @"11", @"11", @"11", @"11", @"11", nil]; NSDictionary *configInfo = [[NSDictionary alloc] initWithObjects: values forKeys:keys]; if (![configInfo writeToFile: strFile atomically: YES]) { NSLog(@"write file error"); }
- iphone创建文件
- iPhone开发-创建、读取、写入文件
- iPhone 下创建、删除、读取、写入文件
- iPhone文件系统:创建、重命名以及删除文件
- 【转】 iPhone文件系统:创建、重命名以及删除文件
- iPhone开发之文件创建、删除、读取、写入
- iPhone开发中关于Xib文件创建UITableViewCell方法
- iphone开发-文件的创建、读入、写、删除
- iphone开发-文件的创建、读入、写、删除
- iPhone开发中关于Xib文件创建UITableViewCell方法
- iphone开发-文件的创建、读入、写、删除。
- iPhone开发中关于Xib文件创建UITableViewCell方法
- 如何在iPhone OS下创建、删除、读取、写入文件
- iphone 开发之pch文件的创建与使用
- iphone开发-文件的创建、读入、写、删除
- iphone 文件
- ios 文件操作 检查文件是否存在 创建文件目录 iphone
- iPhone 创建UIButton
- 关于Servlet的生命周期和线程安全
- 在iPhone游戏中Ogre的UI选择和Ogre的内置UI学习
- 从文件加载至NSData
- NSData加密
- MyEclipse 9.1优化技巧
- iphone创建文件
- curl 介绍
- 视频管理模块代码总结 (1)对上传的flash截取视频并自动生成图片
- SVN忽略文件
- XCode SVN配置
- arch/x86/boot/header.S
- javascript or jquery
- 映泰TH67+的主板前置AC 97音频解决方案
- 调用dll显示对话框