ios中对文件的读与写
在ios中对文件的操作,苹果已经封装好了一个类,开放了对应的ipa,对应的类为:nsfilemanager,文件管理类。
实例化:
[plain]
nsfilemanager *manage = [nsfilemanager defaultmanager];
nsfilemanager *manage = [nsfilemanager defaultmanager];
创建一个文件目录
[plain]
[manage createdirectoryatpath:direcatorypath withintermediatedirectories:yes attributes:nil error:nil];
[manage createdirectoryatpath:direcatorypath withintermediatedirectories:yes attributes:nil error:nil];
返回bool类型,直接判断,创建是否成功。
如果给文件写入数据,如nsdata,就可以:
[plain]
bool iswrite = [_data writetofile:filepath atomically:yes];
bool iswrite = [_data writetofile:filepath atomically:yes];
返回判断,是否成功。
对文件的拷贝:
[plain]
- (bool)copyitematpath:(nsstring *)srcpath topath:(nsstring *)dstpath error:(nserror **)error ns_available(10_5, 2_0);
- (bool)copyitematpath:(nsstring *)srcpath topath:(nsstring *)dstpath error:(nserror **)error ns_available(10_5, 2_0);
转移:
[plain]
- (bool)moveitematpath:(nsstring *)srcpath topath:(nsstring *)dstpath error:(nserror **)error ns_available(10_5, 2_0);
- (bool)moveitematpath:(nsstring *)srcpath topath:(nsstring *)dstpath error:(nserror **)error ns_available(10_5, 2_0);
删除:
[plain]
- (bool)removeitematpath:(nsstring *)path error:(nserror **)error ns_available(10_5, 2_0);
- (bool)removeitematpath:(nsstring *)path error:(nserror **)error ns_available(10_5, 2_0);
文件是否存在:
[plain]
- (bool)fileexistsatpath:(nsstring *)path;
- (bool)fileexistsatpath:(nsstring *)path;
文件是否能读:
[plain]
- (bool)isreadablefileatpath:(nsstring *)path;
- (bool)isreadablefileatpath:(nsstring *)path;
下一篇: 探讨:为什么要研究360搜索引擎优化