Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQLite数据库的Android导出_Android_Database_Sqlite_Permissions - Fatal编程技术网

SQLite数据库的Android导出

SQLite数据库的Android导出,android,database,sqlite,permissions,Android,Database,Sqlite,Permissions,我正在尝试从我的应用程序中导出SQLite数据库,以便为我的应用程序执行导出/导入功能 我使用的示例来自&试图将SQLite数据库(/data/data/com.example.worldcountriesbooks/databases/group.db)从Android设备(三星Galaxy Note)Android 4.0.3导出,但我一直遇到这个错误 12-14 00:56:33.722: I/Failed(14850): java.io.FileNotFoundException: /d

我正在尝试从我的应用程序中导出SQLite数据库,以便为我的应用程序执行导出/导入功能

我使用的示例来自&试图将SQLite数据库(/data/data/com.example.worldcountriesbooks/databases/group.db)从Android设备(三星Galaxy Note)Android 4.0.3导出,但我一直遇到这个错误

12-14 00:56:33.722: I/Failed(14850): java.io.FileNotFoundException: /data/data/com.example.worldcountriesbooks/databases/group.db: open failed: ENOENT (No such file or directory)
我还尝试将
WRITE\u EXTERNAL\u STORAGE
&
WRITE\u MEDIA\u STORAGE
添加到清单文件中,但它不起作用。我可以浏览到我的Android设备上的实际文件,因为它是根文件,但我不能用我的应用程序读取它。知道为什么吗

示例代码:

    try {
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//com.example.worldcountriesbooks/databases//group.db";
            String backupDBPath = "//mnt//sdcard//database.db";
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);

            FileChannel src = new FileInputStream(currentDB).getChannel();
            FileChannel dst = new FileOutputStream(backupDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();
            Toast.makeText(getBaseContext(), backupDB.toString(),
                    Toast.LENGTH_LONG).show();

        }
    } catch (Exception e) {

        Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG)
                .show();
    }

如果文件位于内存中,则应用程序只能从内存中的特殊文件夹中读取。该文件夹的路径由以下程序返回:

getFilesDir().getAbsolutePath()
在您的情况下,它将类似于:

String path= this.getFilesDir().getAbsolutePath() + File.separator + "databases" + File.separator + "group.db";
您可以使用
openFileInput()
阅读它

更多信息:


所以我无法从应用程序中复制sqlite数据库?是的,我已经尝试将其写入sd卡,但它甚至无法打开
/data/data
内部数据库写入sd卡