You need to download the database from the server when you use the call display and query functions,
However, after downloading, database disk image is malformed (code 11) is always reported)
At first, I thought the query statement was incorrect. Later I realized that the error was the same as that when I Parsed the package,
The download format is corrupted.
The solution follows the policy http://blog.csdn.net/jason0539/article/details/21742019,
The code for narrowing down the array read each time is as follows:
Public class DownloadTask {/*** @ param path * @ param filePath storage path * @ param progressDialog progress bar * @ return * @ throws Exception */public static File getFile (String path, string filePath, ProgressDialog progressDialog) throws Exception {URL url = new URL (path); HttpURLConnection connection = (HttpURLConnection) url. openConnection (); connection. setConnectTimeout (2000); connection. setRequestMethod ("GET "); If (connection. getResponseCode () == 200) {int total = connection. getContentLength (); progressDialog. setMax (total); InputStream is = connection. getInputStream (); // get the socket input stream File = new file (filePath); FileOutputStream fos = new FileOutputStream (File ); // file output stream byte [] buffer = new byte [1024]; int len; int progress = 0; while (len = is. read (buffer ))! =-1) {fos. write (buffer); progress + = len; progressDialog. setProgress (progress);} fos. flush (); is. close (); fos. close (); connection. disconnect (); return file;} return null ;}
You can reduce the value of 1024 in this row to avoid damages,
byte[] buffer = new byte[1024];
Because it is always wrong, I even changed it
byte[] buffer = new byte[8];
This is correct, but there is a drawback: downloading is slow, and the downloading database is 16 MB, which is extremely slow,
Temporary solution.
Author: jason0539
Weibo: http://weibo.com/2553717707
Blog: http://blog.csdn.net/jason0539 (reprinted please explain the source)