如何成为Android开发高手
2010-08-31 00:43:00 来源:WEB开发网200
201conn.connect();
202
203printResponseHeader(conn);
204
205if (conn.getResponseCode()==200) {
206
207this.fileSize = conn.getContentLength();//根据响应获取文件大小
208
209if (this.fileSize <= 0) throw new RuntimeException("1无法获知文件大小 ");
210
211
212
213String filename = getFileName(conn);
214
215this.saveFile = new File(fileSaveDir, filename);/* 保存文件 */
216
217Map
218
219if(logdata.size()>0){
220
221for(Map.Entry
222
223data.put(entry.getKey(), entry.getValue()+1);
224
225}
226
227this.block = this.fileSize / this.threads.length + 1;
228
229if(this.data.size()==this.threads.length){
230
231for (int i = 0; i < this.threads.length; i++) {
232
233this.downloadSize += this.data.get(i+1)-(this.block * i);
234
235}
236
237print("已经下载的长度"+ this.downloadSize);
238
239}
240
241}else{
242
243throw new RuntimeException("2服务器响应错误 ");
244
245}
246
247} catch (Exception e) {
248
249print(e.toString());
250
251throw new RuntimeException("3连接不到下载路径 ");
252
253}
254
255}
256
257/**
258
259 * 获取文件名
260
261 */
262
263private String getFileName(HttpURLConnection conn) {
更多精彩
赞助商链接