所以我目前将我的sqlite数据库的备份文件存储在Web服务器上,我遇到的问题是当我尝试将其下载并导入到当前手机中时,出现此错误。
database corruption at line 63697 of [c255889bd9]
2019-11-07 18:01:20.615 26965-26965/com.my.testapp E/SQLiteLog: (11) Invalid First byte:0 of page:4
2019-11-07 18:01:20.615 26965-26965/com.my.testapp E/SQLiteLog: (11) Page (4) content:
2019-11-07 18:01:20.615 26965-26965/com.my.testapp E/SQLiteLog: (11) - 00 01 0F D1 00 0F D1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
2019-11-07 18:01:20.615 26965-26965/com.my.testapp E/SQLiteLog: (11) - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
2019-11-07 18:01:20.615 26965-26965/com.my.testapp E/SQLiteLog: (11) - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
2019-11-07 18:01:20.615 26965-26965/com.my.testapp E/SQLiteLog: (11) - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2D 01 08 00 15 0F 0F 17 33 1B 33 2E 30 30 38 32 31 33
2019-11-07 18:01:20.615 26965-26965/com.my.testapp E/SQLiteLog: (11) - 2E 39 35 32 30 31 39 2D 31 30 2D 32 37 20 31 35 3A 31 31 3A 34 39 32 34 37 31 35 39 34 00 00 00
2019-11-07 18:01:20.615 26965-26965/com.my.testapp E/SQLiteLog: (11) database corruption at line 63741 of [c255889bd9]
2019-11-07 18:01:20.615 26965-26965/com.my.testapp E/SQLiteLog: (11) statement aborts at 3: [SELECT * FROM table ORDER BY idx DESC] database disk image is malformed
2019-11-07 18:01:20.615 26965-26965/com.my.testapp E/DefaultDatabaseErrorHandler: !@ Corruption reported by sqlite (11) on database: /data/user/0/com.my.testapp/databases/MY_DB
2019-11-07 18:01:20.616 26965-26965/com.my.testapp E/SQLiteLog: (11) Invalid type:0 for page:4
但是,如果我将其下载到计算机上,然后手动将其移动到该文件夹中,则可以正常导入。下载时还有其他事情要做吗?这是我使用AsyncTask下载它的代码:
File BACKUP_FILE = new File (contextRef.getExternalFilesDir(null) + "/backup/" + DB_NAME);
if (BACKUP_FILE.exists()) {
if (BACKUP_FILE.delete()){
Log.e("IFS","Deleting previous backup: " + BACKUP_FILE);
}
}
int count;
byte data[] = new byte[4096];
URL sUrl = new URL(URL_FOR_DOWNLOAD);
HttpURLConnection connection = (HttpURLConnection) sUrl.openConnection();
connection.connect();
input = connection.getInputStream();
output = new FileOutputStream(BACKUP_FILE);
while ((count = input.read(data)) != -1)
{
if (isCancelled()) {
input.close();
return null;
}
output.write(data,count);
}
}catch (Exception e){
Log.e("IFS","Error 127: " + e.getMessage());
}