在ios中对文件的操作,苹果已经封装好了一个类,开放了对应的IPA,对应的类为:NSFileManager,文件管理类。
实例化:
NSFileManager *manage = [NSFileManager defaultManager];
[manage createDirectoryAtPath:direcatorypath withIntermediateDirectories:YES attributes:nil error:nil];
如果给文件写入数据,如NSData,就可以:
BOOL isWrite = [_data writeToFile:filepath atomically:YES];
对文件的拷贝:
- (BOOL)copyItemAtPath:(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);
- (BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error NS_AVAILABLE(10_5, 2_0);
- (BOOL)fileExistsAtPath:(NSString *)path;
- (BOOL)isReadableFileAtPath:(NSString *)path;