0
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath;
if (str_FolderName!=nil){
filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@/%@",str_FolderName,str_FileName]];
} else {
filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@",str_FileName]];
}
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableDictionary *data;
if ([fileManager fileExistsAtPath: filePath])
{
//file is exist
data = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
} else {
BOOL Success = [fileManager createFileAtPath:filePath contents:nil attributes:nil];
// sometime return YES, sometime return NO <<< this is my question
if(Success == YES){
data = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
}else{
data = [[NSMutableDictionary alloc] init];
}
}
for (uint32_t u32_Cnt=0;u32_Cnt<arr_Keys.count;u32_Cnt++) {
[data setValue:[NSString stringWithFormat:@"%@",[marr_Data objectAtIndex:u32_Cnt]] forKey:[arr_Keys objectAtIndex:u32_Cnt]];
}
if ([data writeToFile:filePath atomically: YES])
{
NSLog(@"[Save OK]");
return DEF_PASS;
} else {
NSLog(@"[Save Fail]"); <<<< now happened
}
ファイルパスは以下の通りです
を失敗しました:@"/var/mobile/Containers/Data/Application/xxxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx/Documents/mfolder/myfile"
誰かが私を助けることができますか?
私のパスは、フォルダ名が含まれている、私はそれをテストされて別のフォルダなしで成功creatのファイルですが、... – HunterChen
フォルダとファイルを作成して失敗しましたあなたはそれを与えることができますか? – Nirmalsinh
filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@ "/%@ /%@"、str_FolderName、str_FileName]]; – HunterChen