小编Ant*_*des的帖子

导入/导出到android sqlite数据库

我看过几篇关于如何在android中导入和导出数据库的帖子,我找到了这些代码,但我似乎无法使它工作.我收到错误java.io.filenotfoundexception/storage/sdcard0/BackupFolder/DatabaseName:打开失败的ENOENT(没有这样的文件或目录).我改变了一些东西,但我仍然没有找到文件异常

这是我的出口:

private void exportDB() {
        try {
             db.open();
             File newFile = new File("/sdcard/myexport");
            InputStream input = new FileInputStream(
            "/data/data/com.example.mycarfuel/data

bases/MyDatabase");

                OutputStream output = new FileOutputStream(newFile);
                byte[] buffer = new byte[1024];
                int length;
                while ((length = input.read(buffer)) > 0) {
                    output.write(buffer, 0, length);
                }
                output.flush();
                output.close();
                input.close();
                db.close();

            } catch (FileNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
}
Run Code Online (Sandbox Code Playgroud)

和我的导入:

private void importDB() {
        try {
            File …
Run Code Online (Sandbox Code Playgroud)

sqlite android

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

sqlite ×1