NSFileManager *defauleManager = [NSFileManager defaultManager];
NSString *tempPath = NSTemporaryDirectory();
NSLog(@"%@",tempPath);
NSString *thePath = nil;
//创建一个目录: 在temp下创建 MyFoler目录
thePath = [NSString stringWithFormat:@"%@/MyFolder",tempPath];
[defauleManager createDirectoryAtPath:thePath withIntermediateDirectories:YES attributes:nil error:nil];
//写入一个文件 在 temp目录下
NSString *aStr = @"hello world";
thePath = [NSString stringWithFormat:@"%@hello.txt",tempPath];
[aStr writeToFile:thePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
//显示目录内容
NSLog(@"temp目录内容:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]);
//删除一个文件
NSString *deleteStr = @"delete Str";
thePath = [NSString stringWithFormat:@"%@delete.txt",tempPath];
[deleteStr writeToFile:thePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
NSLog(@"temp目录内容:删除之前:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]);
[defauleManager removeItemAtPath:thePath error:nil];
NSLog(@"temp目录内容:删除之后:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]);
//删除一个目录:
thePath = [NSString stringWithFormat:@"%@/TestFoler",tempPath];
[defauleManager createDirectoryAtPath:thePath withIntermediateDirectories:YES attributes:nil error:nil];
NSLog(@"temp目录内容:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]);
[defauleManager removeItemAtPath:thePath error:nil];
NSLog(@"temp目录内容:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]);
//获取目录下的所有文件列表:
NSArray *fileList = [defauleManager contentsOfDirectoryAtPath:tempPath error:nil];
NSLog(@"%@",fileList);
//判断一个目录是否是文件夹
- (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory
[iOS功能]- 对沙盒目录操作
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- .. 1、沙盒 每一个APP都有一个存储空间,就是沙盒。APP之间不能相互通信。iOS 沙盒机制简介沙盒也叫沙箱,...
- Ios沙盒目录清单 1 Documents 用于存储用户生成的文件、其他数据及其他程序不能重新创建的文件,默认文件...
- 前言 在iOS开发中我们经常会遇到一些关于文件的操作,比如说:获取沙盒路径、创建文件、删除文件、向文件内写入内容等...
- 我个人的理解。 刚开始我一直使用 //将NSData类型对象data写入文件,文件名为FileName [data...