我正在做一个数据库中有大量数据的应用程序,所以我需要使用 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/