2010-11-23 106 views

回答

2

你可以在你的下載/上傳代碼中添加一些代碼,如例如:

InputStream is = ...; 
long totalBytesRead = 0; 
long bytesRead = 0; 
long startTime = System.currentTimeMillis(); 

while ((bytesRead = is.read(...))!=0) { 
    // Do something useful with the bytes you read 

    totalBytesRead += bytesRead; 
} 

long endTime = System.currentTimeMillis(); 
float dataRate1 = totalBytesRead/(float) (endTime - startTime); // Bytes/Millisecond 
float dataRate2 = dataRate1 * 1000/1024.0f; // kiloBytes/second 

當然,你也可以定期更新你內在的傳輸速率,同時循環獲得的進展過程中的平均增長率。