+(NSFileManager *)defaultManager;//获得文件管理对象
-(BOOL)createFileAtPath:(NSString *)path contents:(NSData *)data attributes:(NSDictionary *)attr;//创建文件
-(BOOL)fileExistsAtPath:(NSString *)path;//判断一个文件是否存在
-(BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory;
-(BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error;文件复制
-(BOOL)moveItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError**)error;文件移动
-(BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error;/文件删除
// 如何进行浅度遍历
NSString *dirPath=@"/Users/administrator/Desktop/---";
NSFileManager *fm= [NSFileManager defaultManager];
NSArray *arr = [fm contentsOfDirectoryAtPath:dirPath error:nil];
NSLog(@"%@",arr);
//如何进行深度遍历
NSString *dirPath=@"/Users/administrator/Desktop/---";
NSFileManager *fm= [NSFileManager defaultManager];
NSDirectoryEnumerator *dirs=[fm enumeratorAtPath:dirPath];
NSString *path=[dirs nextObject];
while(path!=nil)
{
NSLog(@"%@",path);
path=[dirs nextObject];
}
//创建一个NSFileManager对象
NSFileManager *fm=[NSFileManager defaultManager];
NSString *path=@"/Users/administrator/Desktop/1.txt";
NSString *str=@"这是我创建的一个文件";
// 如何将字符串类型转化为NSdata;
NSData *data=[str dataUsingEncoding:NSUTF8StringEncoding];
BOOL flag=[fm createFileAtPath:path contents:data attributes:nil];
if(flag){
//success;
//读取文件内容,转化为字符串
NSString *fileContent=[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@",fileContent);
}else{
//fail
}