我正在使用以下代码将数据库文件复制到其他文件夹只是为了制作临时写入文件。
BOOL success;
NSArray*dirPath;
NSString*docDir;
NSString*databasePath;
NSString*databaseName=@"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:error:]: source path is nil'”请帮我调试代码谢谢