我正在尝试从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,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!");
- }
- }
如果我取消注释行
- //output.write(data,count);
7-15%下载进度条对话框关闭后,我看到“完成!”在日志中.为什么?