我正在尝试将数据保存在iPhone 5.1模拟器上的文档文件夹中。如何将文件保存在文档文件夹中?
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"myData.json"];
if ([[NSFileManager defaultManager] isWritableFileAtPath:filePath]) {
NSLog(@"Writable");
}else {
NSLog(@"Not Writable");
}
我总是“不可写”。 有什么想法?请帮帮我。
结束你有bu的json文件吗? ndle或动态创建。 –
用于在路径中写入文件u需要将您的json文件创建为nsdata * data或者需要nsstring并使用[data writeAtPath:filePath atomically:YES]; –