我試圖從我的應用程序包複製文件到我的應用程序的文檔目錄。我收到錯誤「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