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

前端 未结 2 1357
抹茶落季
抹茶落季 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:15

    I just ran into this myself a few days ago. Don't force things down the Path path, embrace the NSURL path. It won't take but a short time to get how to use them.

    As to the method, it's simply asking the system to hand you a URL to the standardized documents directory for the application. Use this and most everything regarding where you put new files will be correct.

    0 讨论(0)
  • 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];
    
    0 讨论(0)
提交回复
热议问题