系统版本为ios 6.0下:如果碰到写文件不成功的情况,可能会是以下问题引起的
+(NSString*)writeData:(id)data InFile:(NSString*)fileName
{if (data == nil) {
return nil;
}
NSString *filePath = [[Utilities documentPath] stringByAppendingPathComponent:fileName];
NSFileManager *mgr = [NSFileManager defaultManager];
NSLog(@"curDictionary path :%@",[mgr currentDirectoryPath]);//"/"
[mgr changeCurrentDirectoryPath:[[Utilities documentPath] stringByExpandingTildeInPath]];//更改当前目录为待操作目录下,没有这一步无法写文件
NSLog(@"curDictionary path :%@",[mgr currentDirectoryPath]);//"Documents"
if (![mgr fileExistsAtPath:filePath]) {
[mgr createFileAtPath:filePath contents:nil attributes:nil];
}else{
[mgr removeItemAtPath:filePath error:nil];
}
//[mutData appendBytes:&data length:sizeof(data)];
[data writeToFile:fileName atomically:YES];
NSLog(@"data :%@",data);
NSLog(@"filePath :%@",filePath);
return filePath;
}