【发布时间】:2012-06-18 17:03:22
【问题描述】:
我正在尝试将数据保存在 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");
}
我总是“不可写”。 任何想法?请帮帮我。
【问题讨论】:
-
你有 json 文件在 bundle 中还是动态创建的。
-
要在路径写入文件,您需要将 json 文件创建到 nsdata *data 或您需要 nsstring 并使用 [data writeAtPath:filePath atomically:YES];
标签: iphone nsfilemanager nsdocumentdirectory