iOS文件操作
来源:互联网 发布:java文件上传类 编辑:程序博客网 时间:2024/06/04 00:41
在开发应用程序中,不可避免的会使用到文件读写操作,如何才能高效省力的来处理这些操作呢!那就是把一些常用的文件操作流程写进一个工具类中,每次要用的时候
就直接导入文件,接口调用就可以啦!下面是我写的一个文件操作类。
- #import "FileUtil.h"
- @implementation FileUtil
- /*文件是否存在*/
- + (BOOL)isFileExisted:(NSString *)fileName{
- NSFileManager *fileManager = [NSFileManager defaultManager];
- if(![fileManager fileExistsAtPath:[self getFilePath:fileName]]){
- return NO;
- }
- return YES;
- }
- /*创建指定名字的文件*/
- + (BOOL)createFileAtPath:(NSString *)fileName{
- NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *path = [[array objectAtIndex:0] stringByAppendingPathComponent:fileName];
- NSLog(@"-----%@:", path);
- NSFileManager *fileManager = [NSFileManager defaultManager];
- if(![fileManager fileExistsAtPath:path]){
- [fileManager createFileAtPath:path contents:nil attributes:nil];
- return YES;
- }
- return NO;
- }
- /*创建指定名字的文件夹*/
- + (BOOL)createDirectoryAtPath:(NSString *)fileName{
- NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *path = [[array objectAtIndex:0] stringByAppendingPathComponent:fileName];
- NSLog(@"-----%@:", path);
- NSFileManager *fileManager = [NSFileManager defaultManager];
- if(![fileManager fileExistsAtPath:path]){
- NSError *error = nil;
- [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
- return YES;
- }
- return NO;
- }
- /*得到文件路径*/
- + (NSString *)getFilePath:(NSString *)fileName{
- NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *path = [[array objectAtIndex:0] stringByAppendingPathComponent:fileName];
- return path;
- }
- /*删除文件*/
- + (BOOL)deleteFileAtPath:(NSString *)fileName{
- NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *path = [[array objectAtIndex:0] stringByAppendingPathComponent:fileName];
- NSFileManager *fileManager = [NSFileManager defaultManager];
- if(![fileManager fileExistsAtPath:path]){
- return NO;
- }
- [fileManager removeItemAtPath:path error:nil];
- return YES;
- }
- /*得到PList文件*/
- + (NSMutableDictionary *)getPlistFile:(NSString *)fileName{
- NSBundle *bundle = [NSBundle mainBundle];
- NSString *path = [bundle pathForResource:fileName ofType:@"plist"];
- return [[NSMutableDictionary alloc] initWithContentsOfFile:path];
- }
- /*获取plist文件目录*/
- + (NSString *)getPListFilePath:(NSString *)fileName{
- NSBundle *bundle = [NSBundle mainBundle];
- return [bundle pathForResource:fileName ofType:@"plist"];
- }
- @end
0 0
- iOS 文件相关操作
- iOS中的文件操作
- iOS开发 文件操作
- ios 文件操作实例
- ios常用文件操作
- ios文件的操作
- IOS常用文件操作
- iOS文件操作
- IOS文件操作
- ios 操作plist文件
- (转载)ios文件操作
- iOS文件操作 NSFileManager
- ios 文件/目录操作
- ios文件读写操作
- ios 文件操作
- IOS 文件操作
- IOS文件常用操作
- IOS文件操作
- Proxy与Agent的内在联系与区别
- openstack中虚拟机CPU与内存布局设计(一)
- ListView与GridView中SetEmptyView方法的使用,及触发条件
- Ubuntu14.04.3 64b 无GPU 安装caffe
- p243 第五题
- iOS文件操作
- Oracle建立表空间和用户
- android:windowSoftInputMode属性介绍
- bzoj 2049(link cut tree)
- JS+html5实现图片上传预览
- android 系统级的开机启动程序
- hdu 2112 HDU Today(map+Floyd)
- CentOS已经安装命令,但提示找不到
- servlet3.0 之监听器(@WebListener)