系統版本爲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;
}