第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

正在回答

2 回答

下載部分的讀取和寫入有問題,需要檢查下代碼

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕粉2041172413

是嚴(yán)格按照視頻上的讀取和寫入的呀,還是不能安裝,文件大小也是正常的
2016-12-08 回復(fù) 有任何疑惑可以回復(fù)我~

/**

* 下載線程

*/

class DownloadThread extends Thread {

private ThreadInfo threadInfo; // 線程信息


// public boolean isFinished = false;


public DownloadThread(ThreadInfo threadInfo) {

this.threadInfo = threadInfo;

Log.i(tag, "thread info = " + threadInfo);

}


@Override

public void run() {

URL url = null;

HttpURLConnection con = null; // http鏈接

RandomAccessFile accessFile = null; // 下載文件

InputStream inputStream = null; // 輸入流

try {


int start = threadInfo.getStart() + threadInfo.getFinished(); // 讀取文件的位置

// int startPos = blockSize * (threadId - 1);//開始位置 ?

// int endPos = blockSize * threadId - 1;//結(jié)束位置?

?

// start 初始化下載鏈接

url = new URL(threadInfo.getUrl());

con = (HttpURLConnection) url.openConnection();

con.setAllowUserInteraction(true); ?

con.setRequestMethod("GET");

con.setConnectTimeout(5000);

con.setRequestProperty("Range", "bytes=" + start + "-"

+ threadInfo.getEnd()); // 設(shè)置讀取文件的位置,和結(jié)束位置

// end 初始化下載鏈接

// start 初始化下載到本地的文件

accessFile = new RandomAccessFile(new File(

mTaskInfo.getFilePath(), mTaskInfo.getFileName()),

"rwd");

accessFile.seek(start); // 設(shè)置開始寫入的位置

// end 初始化下載到本地的文件

int responseCode = con.getResponseCode();

if ((con.getResponseCode() == HttpURLConnection.HTTP_PARTIAL)

|| (con.getResponseCode() == HttpURLConnection.HTTP_OK)) {

inputStream = con.getInputStream();

int finished = threadInfo.getFinished(); // 已經(jīng)下載的長度

// int len = threadInfo.getEnd()-threadInfo.getStart();

// //本線程要下載的長度

int readLen = -1; // 讀取的長度

byte[] buffer = new byte[1024 * 4];

long time = System.currentTimeMillis();


// start 讀取輸入流寫入文件

while ((readLen = inputStream.read(buffer)) != -1) {

accessFile.write(buffer, 0, readLen);

// Log.i(tag, "readLen = " + readLen);

finished += readLen;

threadInfo.setFinished(threadInfo.getFinished()+readLen); // 設(shè)置已經(jīng)下載進(jìn)度

if (System.currentTimeMillis() - time > 2000) {

// Log.i(tag, "readLen = " + readLen);

notifyProgress(threadInfo.getId(), threadInfo.getFinished()); // 每隔2秒通知下載進(jìn)度

time = System.currentTimeMillis();

}

// start 停止下載,保存進(jìn)度

if (isPause) {

Log.i(tag,

"pause name = " + mTaskInfo.getFileName());

notifyProgress(threadInfo.getId(), threadInfo.getFinished()); // 通知下載進(jìn)度

mThreadDao.updateThread(threadInfo.getUrl(),

threadInfo.getId(), threadInfo.getFinished()); // 更新數(shù)據(jù)庫對應(yīng)的線程信息

return;

}

// end 停止下載,保存進(jìn)度

}

// end 讀取輸入流寫入文件


// mThreadDao.updateThread(threadInfo.getUrl(),threadInfo.getId(),finished);

// isFinished = true;

// checkIsAllThreadFinished();

// broadcastFinished(threadInfo.getId(),finished);

notifyProgress(threadInfo.getId(), finished);

}

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} finally {


try {

if (inputStream != null) {

inputStream.close();

}

if (accessFile != null) {

accessFile.close();

}

if (null != con) {

con.disconnect();

}


} catch (IOException e) {

e.printStackTrace();

}


}

super.run();

}

}


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Android-Service系列之多線程斷點(diǎn)續(xù)傳下載
  • 參與學(xué)習(xí)       21811    人
  • 解答問題       60    個(gè)

本視頻教程主要代領(lǐng)我們要學(xué)習(xí)的多線程續(xù)傳下載程序的開發(fā)

進(jìn)入課程

下載下來的文件不能安裝

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號