我有这样的代码,从主包复制.txt文件到文件目录。这在模拟器上工作,但无法在设备上工作。我通过删除文档目录中的txt文件并再次运行应用程序来验证它在Simulator上的工作。当我在设备上运行应用程序时,copyItemAtPath失败。这是我的代码。copyItemAtPath在模拟器上工作,但在设备上失败
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath= [documentsDirectory stringByAppendingPathComponent:@"zipFileName.txt"];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success)
{
return;
}
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"zipFileName.txt"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
我试过清洗和再次建设,我甚至重新启动手机,但没有任何工作。
ERROR:2012-05-08 16:13:19.487 balita [162:707] *断言故障 - [视图控制器currentJsonFile],/Users/diffy/Documents/balita/balita/ViewController.m: 144 2012-05-08 16:13:19.496 balita [162:707] 由于未捕获的异常'NSInternalInconsistencyException'导致终止应用程序,原因:'无法用消息创建可写的数据库文件'操作无法完成。 (可可错误260.)'。' * *第一掷调用堆栈:
你从[错误localizedDescription]得到什么错误信息? – Vin
我已更新我的问题,附上错误消息。 – Diffy
设备和模拟器之间存在区分大小写区别。设备区分大小写。 – user523234