讀取輸入流循環(huán)提前結(jié)束
is?=?conn.getInputStream(); //?讀取文件 int?len?=-1; byte[]?buffer?=?new?byte[4*1024]; long?time?=?System.currentTimeMillis(); while?((len?=?is.read(buffer))?!=?-1)?{ //?寫入文件 raf.write(buffer,?0,?len); if?(System.currentTimeMillis()?-?time?>?500)?{ time?=?System.currentTimeMillis(); //?把下載的進(jìn)度發(fā)送廣播道Activity mFinished?+=?len; intent.putExtra("progress",?(mFinished?*?100)/?mFileInfo.getLength()); Log.i("下載進(jìn)度:", mFinished?+?"--"?+?mFileInfo.getLength() +?"--"?+?(mFinished?*?100) /?mFileInfo.getLength()?+?"%"); mContext.sendBroadcast(intent); } //?下載暫停時(shí),保存下載進(jìn)度 if?(isPause)?{ mDao.updataThread(mThreadInfo.getUrl(), mThreadInfo.getId(),?mFinished); System.out.print("下載暫停"); return; } } //?下載結(jié)束后刪除線程信息 mDao.deleteThread(mThreadInfo.getUrl(),?mThreadInfo.getId()); System.out.print("下載完成"); }
網(wǎng)絡(luò)內(nèi)容獲取區(qū)間設(shè)置也正確
conn.setRequestProperty("Range",?"bytes="?+?start?+?"-" +?mThreadInfo.getEnd());
while循環(huán)每次都提前結(jié)束。
2015-09-06
并不是while提前結(jié)束,你想想打印下載進(jìn)度的條件是不是有什么不妥的地方?