`
linqianqiu
  • 浏览: 9198 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

Objective-c 复制资源文件到Document

    博客分类:
  • IOS
阅读更多
在做sqlite数据库连接的时候,把项目中的数据库复制到沙盘中的Document目录,这样方便增删改操作

复制文件需要文件的路径和新文件的路径

首先获取Document路径
NSString *document  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];


然后创建新文件路径
NSString *newFile = [document stringByAppendingPathComponent:@"test.sqlite"];


接着获取资源文件路径
NSString *oldFile = [NSBundle mainBundle] pathForResource:@"test" ofType:@"sqlite"];


最后使用NSFileManager复制文件
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager copyItemAtPath:oldFile toPath:newFile error:nil];
1
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics