I'm trying to download large file from Internet (>20Mb)
private class DownloadTask extends AsyncTask<DatabaseInfo, Integer, String> {
private DatabaseInfo info;
protected String doInBackground(DatabaseInfo... dbInfo) {
int count;
info = dbInfo[0];
try {
URL url = new URL(dbInfo[0].dbPath);
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream("/sdcard/db.zip");
byte data[] = new byte[1024];
int total = 0;
while ((count = input.read(data)) != -1) {
//output.write(data, 0, count);
total += count;
if (total % 10240 == 0) {
publishProgress(total);
}
}
output.flush();
output.close();
input.close();
}
catch (Exception e) {
Log.e("err", e.getMessage());
}
return null;
}
protected void onProgressUpdate(Integer... total) {
int perc = (int) ((float) total[0] / (float) info.dbZipSize * 100);
mProgressDialog.setProgress(perc);
}
protected void onPostExecute(String s) {
dismissDialog(DIALOG_PROGRESS);
Log.e("err", "finish!");
}
}
If I uncomment line
//output.write(data, 0, count);
after 7-15% downloading progressbar dialog dismiss and I see "finish!" in Log. Why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…