[OC学习笔记]文件管理

来源:互联网 发布:西安淘宝代运营 编辑:程序博客网 时间:2024/05/01 06:20

  • 管理文件和目录NSFileManager

1. 管理文件和目录:NSFileManager

方法 描述 -(NSData ) contentsAtPath: *path 从一个文件读取数据 -(BOOL) createFileAtPath: path contents: (NSData ) *data attributes: attr 向一个文件写入数据 -(`BOOL) removeItemAtPath: path error: err 删除一个文件 -(BOOL) moveItemAtPath: from toPath: to error: err 重命名或移动一个文件(to不能是已存在的) -(BOOL) copyItemAtPath: from toPath: to error: err 复制一个文件(to不能是已存在的) -(BOOL) contentsEqualAtPath: path1 andPath: path2 比较这两个文件的内容 -(BOOL) fileExistsAtPath: path 测试文件是否存在 -(BOOL) isReadableFileAtPath: path 测试文件是否存在且是可读文件 -(BOOL) isWritableFileAtPath: path 测试文件是否存在且是可写文件 -(NSDictionary ) attributesOfItemAtPath: *path error: err 获取文件的属性 -(BOOL) setAttributesOfItemAtPath: attr error: err 更改文件的属性 —————-目录—————- —————目录—————- -(NSString *) currentDirectoryPath 获取当前目录 -(BOOL) changeCurrentDirectoryPath: path 更改当前目录 -(BOOL) copyItemAtPath: from toPath: to error: err 复制目录结构(to不能是已存在的) -(BOOL) createDirectoryAtPath: path withIntermediateDirectories: (BOOL) flag attributes: attr 创建一个新目录 -(NSArray ) contentsOfDirectoryAtPath: *path error: err 列出目录内容 -(NSDirectoryEnumerator ) enumeratorAtPath: *path 枚举目录的内容 -(BOOL) removeItemAtPath: path error: err 删除空目录 -(BOOL) moveItemAtPath: from toPath: to error: err 重命名或移动一个目录(to不能是已存在的)

NSFileManager对象的创建

NSFileManager *fm = [NSFileManager defaultManager];
0 0