android - 在android中插入外部数据库

标签 android database sqlite

我正在做一个数据库中有大量数据的应用程序,所以我需要使用 SQlite 浏览器创建一个外部数据库并将其放入我的应用程序中

我的问题是

我看不到数据/数据/数据库,因为我的手机没有 root 并且由于某些原因我无法 root

我在 Eclipse IDE 中使用 BlueStack 模拟器

请帮忙

谢谢

最佳答案

您可以创建您的数据库并将其放在您的 Assets 目录中 并在第一次使用时复制到数据目录。

try {

    String destPath = "/data/data/" + getPackageName()
            + "/databases/YOURDbFileName";

    File f = new File(destPath);
    if(!f.exists()){
    Log.v(TAG,"File Not Exist");
    InputStream in = getAssets().open("YOURDbFileName");
    OutputStream out = new FileOutputStream(destPath);

    byte[] buffer = new byte[1024];
    int length;
    while ((length = in.read(buffer)) > 0) {
        out.write(buffer, 0, length);
    }
    in.close();
    out.close();
    }

} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    Log.v("TAG","ioexeption");
    e.printStackTrace();
}

关于android - 在android中插入外部数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32285144/

相关文章:

python - 如何使用 Django/Python 在 SQLite 中存储获取的 JSON 数据

sql - 匿名SQLite数据库?

android - 提供网站以在 Android 平板电脑上离线查看的最佳方式

android - 空对象引用上 android.view.View android.view.View.findViewById(int) 的 onCreateOptionsMenu 问题

android - 错误 :(19, 0) 找不到 Gradle DSL 方法: 'android()'

sql - 在规范化数据库时从单个表插入多个表

arrays - 获取元素 mongodb 聚合的索引

数据库一对一关系实现

sqlite - 如何在移动应用程序的SQLite中的同一数据库中创建多个表?

java - 创建 android studio 库后,我无法添加许多 comman 依赖项