我正在使用以下代碼將數據庫文件複製到其他文件夾中以創建臨時寫入文件。無法將數據庫文件複製到其他文件夾
BOOL success;
NSArray*dirPath;
NSString*docDir;
NSString*databasePath;
NSString*[email protected]"EXPENSES";
//path for database
dirPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docDir=[dirPath objectAtIndex:0];
databasePath=[docDir stringByAppendingPathComponent:databaseName];
NSLog(@" docDir %@",docDir);
//check if present
NSFileManager*fm=[NSFileManager defaultManager];
success=[fm fileExistsAtPath:databasePath];
if(success)
{
NSLog(@"DATA BASE Already present");
}
else
{
//Copy from bundle to DocumentsDirectory on first run. Where DB won't be available in DocumentsDirectory.
NSString*bundlePath=[[NSBundle mainBundle] pathForResource:@"EXPENSES" ofType:@""];
NSError*error;
success=[fm copyItemAtPath:bundlePath toPath:databasePath error:&error];
if(success)
{
NSLog(@"DATA BASE Created successfully");
}
} // End of else when DB not present in documents directory.
但該文件沒有複製,而不是應用程序崩潰與錯誤「的理由:‘* - [的NSFileManager copyItemAtPath:toPath:錯誤:]:源路徑是零’」請幫我調試代碼謝謝
我還沒有提到任何擴展,在它工作之前,但我沒有知道發生了什麼突然它現在不工作 – Deepak
@Deepak:請檢查該文件仍然在主包 –
感謝您的快速回復。它仍然在主要捆綁中。 – Deepak