如何使用Android Studio从模拟器中的数据文件夹访问SQLite数据库?

时间:2017-05-01 13:51:47

标签: android database sqlite android-studio

我正试图从Android Studio中的Android设备管理器中的数据文件夹访问SQLite数据库。我正在使用Nexus_4_API_24仿真器。当我尝试打开数据文件夹时,没有任何东西打开,就像它是空的一样。我在地狱中搜索过,但仍未找到问题的答案。

由于

1 个答案:

答案 0 :(得分:0)

您可以将数据库复制到您知道自己有权访问的地方。如果内存服务只有您的应用程序可以访问文件夹/data/data/yourapp/yourdb.sql,所以除非您的文件浏览器具有访问此文件夹的特定权限,否则最好将其复制到其他位置。 我知道你可以使用这个来复制文件,但从来没有用数据库测试它,

     public static void copyFile(String src, String dst) throws IOException
{
    FileChannel inChannel = new FileInputStream(src).getChannel();
    FileChannel outChannel = new FileOutputStream(dst).getChannel();
    try
    {
        inChannel.transferTo(0, inChannel.size(), outChannel);
    }
    finally
    {
        if (inChannel != null)
            inChannel.close();
        if (outChannel != null)
            outChannel.close();
    }
}

src和dst类似于:

      src=mContext.getFilesDir().getAbsolutePath()+"/yourdbname.sql";
      dst=mContext.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath()+"/yourdbname.sql";

然后在文件资源管理器jsut中转到sdcard / Android / yourapp / Documents / yourdb.sql

希望我回答了这个问题,我可以帮助你