在做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];