A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Latinno 中级黑马   /  2016-4-21 23:54  /  607 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

// 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];

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马