我正在尝试将一个文件从我的应用程序包复制到我的应用程序的文档目录。我收到一个错误,“Cocoa Error 262”。我究竟做错了什么?这是我的代码:
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreData.sqlite"];
NSURL *initialURL = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"CoreData" ofType:@"sqlite"]];
NSError *error = nil;
if (![[NSFileManager defaultManager] fileExistsAtPath:[initialURL absoluteString]]) {
NSLog(@"Original does not exist. \nPath: %@", [initialURL absoluteString]);
}
if (![[NSFileManager defaultManager] fileExistsAtPath:[storeURL absoluteString]]) {
NSLog(@"Destination file does not exist. \nPath: %@", [storeURL absoluteString]);
[[NSFileManager defaultManager] copyItemAtURL:initialURL toURL:storeURL error:&error];
NSLog(@"Error: %@", [error description]);
}
最佳答案
问题是您正在使用普通的旧文件路径初始化 URL。
NSURL *initialURL =
[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"CoreData"
ofType:@"sqlite"]];
改用[NSURL fileURLWithPath:]
。
关于iphone - 我这里的副本有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7237716/