IPhone软件安装时写入配置文件

运行下边的代码前,先在Copy Bundle Resources下加入我们需要写入的文件     

  documentPath = [[NSString alloc] initWithFormat:@"%@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];

        

        NSString*realPath=[documentPath stringByAppendingPathComponent:DATEBASE_FILE_NAME];

//读入程序中本身文件

        NSString*srcPath=[[NSBundle mainBundle]pathForResource:@"mes" ofType:@"sqlite3"];        

        NSFileManager*fileManager=[NSFileManager defaultManager];
        if (![fileManager fileExistsAtPath:realPath]) {

            NSError*error;

//把程序文件读入 手机的documents

            [fileManager copyItemAtPath:srcPath toPath:realPath error:&error];

        }


你可能感兴趣的:(Iphone,开发)