将sqlite文件复制到Documents文件夹后,文件变空

NCF*_*USN 3 sqlite cocoa-touch ios

我有.db文件的问题,复制到Documents目录后获得0 KB的大小,而原始文件是137KB.我试图在SQLite Manager中打开我复制的文件.它打开,不抱怨文件损坏......它只是不包含单个表.

我复制文件的代码:

- (void) createEditableDatabase
{
    BOOL success; 
    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    NSError *error;
    NSString *writableDB = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"yc_ch.db"];
    success = [fileManager fileExistsAtPath:writableDB];
    if (success)
    {
        return;
    }
    NSString *defaultPath = [[NSBundle mainBundle] pathForResource:@"yc_ch" ofType:@"db"];
    error = nil;
    success = [fileManager copyItemAtPath:defaultPath toPath:writableDB error:&error];
    if (!success) 
    {
        NSAssert1(0, @"Failed to create writable database file:%@", [error localizedDescription]);
    }
}
Run Code Online (Sandbox Code Playgroud)

检查文件是否存在,如果不是副本.检查发生在RootViewController中

- (void)viewDidLoad
{
    self.subCountriesArr=[[NSMutableArray alloc]initWithCapacity:1];
    NSMutableArray *subCountriesTemp=[[[NSMutableArray alloc]init]autorelease];

    DBAccess *dbAccess=[[DBAccess alloc]init];
    [dbAccess createEditableDatabase]; //method to copy file
    subCountriesTemp=[dbAccess getSubCountries];

    [dbAccess closeDataBase];
    [dbAccess release];
}
Run Code Online (Sandbox Code Playgroud)

所以,这对我来说很奇怪.有什么帮助吗?先感谢您.

小智 7

毕竟,我确实喜欢这个.它对我有用.

1)单击.db文件.

2)然后在右侧找到fileInspector,单击文件检查器

3)检查.db文件的目标成员资格是否选中复选框.

4)如果没有选中复选框

希望它会起作用......