六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 36|回复: 0

db数据库的处理

[复制链接]

升级  82%

292

主题

292

主题

292

主题

进士

Rank: 4

积分
910
 楼主| 发表于 2013-1-15 02:27:41 | 显示全部楼层 |阅读模式
final String DB_DESTINATION = "/data/data/YOUR_PACKAGE_NAME/databases/MyDatabaseFile.db"
 
// Check if the database exists before copying 
boolean initialiseDatabase = (new File("DB_DESTINATION")).exists(); 
if (initialiseDatabase == true) { 
 
    // Open the .db file in your assets directory 
    InputStream is = getContext().getAssets().open("MyDatabaseFile.db"); 
 
    // Copy the database into the destination 
    OutputStream os = new FileOutputStream(DB_DESTINATION); 
    byte[] buffer = new byte[1024]; 
    int length; 
    while ((length = is.read(buffer)) > 0){ 
        os.write(buffer, 0, length); 
    } 
    os.flush(); 
 
    os.close(); 
    is.close(); 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表