【发布时间】:2014-06-02 12:04:00
【问题描述】:
我已经创建了我的 sqlite 数据库 (employeertest.sql) 并将它放在 Assets 文件夹中,然后运行
这段代码。
不幸的是在getBaseContext().getAssets().open("employeertest")编译器说No such file or directory
try {
String destPath = "/data/data/" + getPackageName() +"/databases";
File f = new File(destPath);
f.mkdirs();
f.createNewFile();
//---copy the db from the assets folder into
// the databases folder---
CopyDB(getBaseContext().getAssets().open("employeertest"),
new FileOutputStream(destPath + "/employeertest"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
【问题讨论】:
-
尝试在目录字符串中使用双斜杠或双反斜杠作为分隔符。
-
试试getBaseContext().getAssets().open("employeertest.sql")...你需要文件扩展名。
-
@JanBo 好的,它解决了我的问题,但现在它说
no such table : test用于查询select * from test -
好吧,你要么在你的数据库中没有那个表 :) 我非常怀疑,要么你从文件中正确地初始化了数据库。把数据库打开代码和查询代码发给你。
-
@JanBo 实际上我有,我使用 firefox 插件创建了我的数据库。请看一下这个链接。 stackoverflow.com/questions/934237/…