备份和恢复SQLite数据库到SD卡 [英] Backup and restore SQLite database to sdcard

查看:124
本文介绍了备份和恢复SQLite数据库到SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何备份我的数据库到我的应用程序自动SD卡? 而后来,我怎么恢复呢?

How can I backup my database to the sdcard automatically in my app? And afterward, how do I restore it?

推荐答案

下面是我的code:

    // Local database
    InputStream input = new FileInputStream(from);

    // create directory for backup
    File dir = new File(DB_BACKUP_PATH);
    dir.mkdir();

    // Path to the external backup
    OutputStream output = new FileOutputStream(to);

    // transfer bytes from the Input File to the Output File
    byte[] buffer = new byte[1024];
    int length;
    while ((length = input.read(buffer))>0) {
        output.write(buffer, 0, length);
    }

    output.flush();
    output.close();
    input.close();

这篇关于备份和恢复SQLite数据库到SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆