如何成为Android开发高手
2010-08-31 00:43:00 来源:WEB开发网264
265String filename = this.url.toString().substring(this.url.toString().lastIndexOf('/') + 1);
266
267if(filename==null || "".equals(filename.trim())){//如果获取不到文件名称
268
269for (int i = 0;; i++) {
270
271String mine = conn.getHeaderField(i);
272
273if (mine == null) break;
274
275if("content-disposition".equals(conn.getHeaderFieldKey(i).toLowerCase())){
276
277Matcher m = Pattern.compile(".*filename=(.*)").matcher(mine.toLowerCase());
278
279if(m.find()) return m.group(1);
280
281}
282
283}
284
285filename = UUID.randomUUID()+ ".tmp";//默认取一个文件名
286
287}
288
289return filename;
290
291}
292
293
294
295/**
296
297 * 开始下载文件
298
299 * @param listener 监听下载数量的变化,如果不需要了解实时下载的数量,可以设置为null
300
301 * @return 已下载文件大小
302
303 * @throws Exception
304
305 */
306
307public int download(DownloadProgressListener listener) throws Exception{
308
309try {
310
311if(this.data.size() != this.threads.length){
312
313this.data.clear();
314
315for (int i = 0; i < this.threads.length; i++) {
316
317this.data.put(i+1, this.block * i);
318
319}
320
321}
322
323for (int i = 0; i < this.threads.length; i++) {
324
325int downLength = this.data.get(i+1) - (this.block * i);
326
327if(downLength < this.block &&
更多精彩
赞助商链接