iPhone: How to copy a file from resources to documents?

前端 未结 2 1380
抹茶落季
抹茶落季 2020-12-15 10:42

I just started with iPhone development. In one of the example where I had to display some data stored in sqlite db in a table view in a tabbar controller, I had to move a sq

2条回答
  •  不知归路
    2020-12-15 11:20

    heres a simple way to do it:

        NSFileManager *fmngr = [[NSFileManager alloc] init];
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"mydb.sqlite" ofType:nil];
        NSError *error;
        if(![fmngr copyItemAtPath:filePath toPath:[NSString stringWithFormat:@"%@/Documents/mydb.sqlite", NSHomeDirectory()] error:&error]) {
             // handle the error
             NSLog(@"Error creating the database: %@", [error description]);
    
        }
        [fmngr release];
    

提交回复
热议问题