在做sqlite数据库连接的时候,把项目中的数据库复制到沙盘中的Document目录,这样方便增删改操作
复制文件需要文件的路径和新文件的路径
首先获取Document路径
然后创建新文件路径
接着获取资源文件路径
最后使用NSFileManager复制文件
复制文件需要文件的路径和新文件的路径
首先获取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];
本文介绍如何将SQLite数据库从项目资源复制到iOS应用的Document目录中,包括获取路径、创建新文件路径及使用NSFileManager进行文件复制的具体步骤。
73

被折叠的 条评论
为什么被折叠?



