我试图从我的应用程序包复制文件到我的应用程序的文档目录。我收到错误“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]);
}
什么是正确的方案,你从哪里得到这些信息? – Moshe
不要使用+ URLWithString:除非你想建立整个“file:/// path/to/file”路径。但为什么你会在+ fileURLWithPath时为你做这件事。 – kperryua
从[链接](http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html)获得了信息正确的方案几乎意味着你的网址被格式化。 – smitec