NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// 获取document目录
NSString *documentDirectory = [paths objectAtIndex:0];
// 追加文件系统路径
NSString *path = [documentDirectory stringByAppendingPathComponent:XXX];//XXX文件名
MyLog(@"path = %@",path);
if (![[NSFileManager defaultManager] fileExistsAtPath:path])
{
// Copy database file
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"XXX" ofType:nil];//XXX文件名
MyLog(@"数据库本地filePath --- %@", filePath);
[[NSFileManager defaultManager] copyItemAtPath:filePath toPath:path error:nil];
}
用上面的方法可以实现将程序里的文件保存至沙盒中(Documents文件下)。
将程序中文件保存至沙盒中
最新推荐文章于 2022-12-02 15:04:38 发布