我正在使用以下代码将数据库文件复制到其他文件夹中以创建临时写入文件。无法将数据库文件复制到其他文件夹
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