黑马程序员技术交流社区

标题: NSFileManager的一些功能总结 [打印本页]

作者: Latinno    时间: 2016-4-21 23:54
标题: NSFileManager的一些功能总结
// NSFileManager 总结
        
        NSFileManager *fm1 = [NSFileManager defaultManager];
        
        // 1.从一个文件中读取数据  返回NSData 对象
        
        [fm1 contentsAtPath:@"path"];
        
        // 2.向一个文件写入数据 返回BOOL值
        
        [fm1 createFileAtPath:@"path" contents:[[NSData alloc] init] attributes:attr];
        
        // 3.删除一个文件  返回BOOL值
        
        [fm1 removeItemAtPath:@"path" error:nil];
        
        // 4.重命名或者移动一个文件(to不能是已存在的路径) 返回BOOL值
        
        [fm1 moveItemAtPath:@"path" toPath:@"to path" error:nil];
        
        // 5.复制文件 (to不能是已存在的路径) 返回BOOL值
        
        [fm1 copyItemAtPath:@"path" toPath:@"to path" error:nil];
        
        // 6.比较这两个文件的内容 返回BOOL值
        
        [fm1 contentsEqualAtPath:@"path" andPath:@"otherpath"];
        
        // 7.测试文件是否存在  a.并且是否执行读操作 b.写操作 返回BOOL值
        
        [fm1 fileExistsAtPath:@"path"];
        
        [fm1 isReadableFileAtPath:@"path"];
        
        [fm1 isWritableFileAtPath:@"path"];
        
        // 8.更改文件的属性 返回BOOL值
        // [fm1 setAttributes:@"gaigaikan" ofItemAtPath:@"path" error:nil];
        
        // [fm1 setAttributes:<#(nonnull NSDictionary<NSString *,id> *)#> ofItemAtPath:<#(nonnull NSString *)#> error:<#(NSError * _Nullable __autoreleasing * _Nullable)#>];
        
        // 字符串写入文档的方法
        
        NSString *test = @"65464";
        
        [test writeToFile:@"path" atomically:YES encoding:NSUTF8StringEncoding error:nil];
        
        // 9.获取文件的属性
        [fm1 attributesOfItemAtPath:@"path" error:nil];





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2