【发布时间】:2010-08-13 19:10:05
【问题描述】:
我的一个应用程序从服务器下载数据库。 当我将应用程序安装到手机上时,它会正确下载文件并加载信息,没有抛出异常或任何东西。
但是,当我将 apk 上传到 Android Market Place 并将其下载到手机上时,应用程序会下载数据库然后崩溃,说 sqlite 处理程序无法打开数据库。
这是代码的进展:
在 SQLiteOpenHelper 中:
this.FULL_DB_PATH = new String(this.getWritableDatabase().getPath());
this.getWritableDatabase();
// Code for retrieving the database off of the server:
private void copyDataBase(){
InputStream myInput=null;
OutputStream myOutput=null;
try{
// opening connections
URL url = new URL("server_url_here");
URLConnection ucon=url.openConnection();
myInput = ucon.getInputStream();
myOutput = new FileOutputStream(this.FULL_DB_PATH);
// write to the db here
byte[] buffer = new byte[1024*1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
catch(Exception e)
{
try{
myOutput.flush();
myOutput.close();
myInput.close();
}
catch(Exception es){}
}
}
我不知道为什么我的同事要保存带有 mp3 扩展名的数据库,但是......当我们安装 apk ad-hoc 时它可以工作。
为:
myOutput = new FileOutputStream(this.FULL_DB_PATH);
我也试过了:
myOutput = this.getApplicationContext().openFileOutput(this.FULL_DB_PATH, Context.MODE_WORLD_READABLE);
但这也不起作用。
非常感谢任何帮助!我已经为此扯了几个小时的头发,我只是希望它结束哈哈。
【问题讨论】:
标签: android database sqlite file-io download