首页 > 数据库技术 > 详细

拷贝数据库文件到路径

时间:2014-12-05 19:26:04      阅读:301      评论:0      收藏:0      [点我收藏+]

NSFileManager *fileManager = [NSFileManager defaultManager];

    NSError *error;

    

    //复制本地数据库文件到安装目录

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentDirectory = [paths objectAtIndex:0];

    //APP安装目录中的document目录路径

    NSString *dbPath = [documentDirectory stringByAppendingPathComponent:@"CountryDictionary.db"];

    

    if ([fileManager fileExistsAtPath:dbPath]==NO) {

        //项目中的数据库文件路径

        NSString *resourcePath = [[NSBundle mainBundle]pathForResource:@"CountryDictionary" ofType:@"db"];

        [fileManager copyItemAtPath:resourcePath toPath:dbPath error:&error];

    } else {

        //更新APP Documnet目录的数据库文件,如果存在则先删除再复制最新的数据库文件过去。等本地数据库设计好后,下面的代码需要注释掉。

        NSError *error;

        if ([fileManager removeItemAtPath:dbPath error:&error]!=YES) {

            NSLog(@"unable to delete file %@",[error localizedDescription]);

        }

        

        NSString*resourcePath =[[NSBundle mainBundle] pathForResource:@"CountryDictionary" ofType:@"db"];

        [fileManager copyItemAtPath:resourcePath toPath:dbPath error:&error];

    }

拷贝数据库文件到路径

原文:http://blog.csdn.net/zh_2608/article/details/41750313

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!