真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Android中怎么利用Http下載文件到手機(jī)

Android 中怎么利用Http下載文件到手機(jī),針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。

為商城等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及商城網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、商城網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!

訪問(wèn)Internet和保存文件到SDCard上,首先要在mainifest.xml文件中加上下面的權(quán)限。

  

gettextfilestring(String url)獲取文本文件內(nèi):

public String gettextfilestring(String url){                 InputStream input =getinputStream(url);                 StringBuffer sb = new StringBuffer("");                 BufferedReader bfr = new BufferedReader(new InputStreamReader(input));                 String line = "";                 try {                         while((line=bfr.readLine())!=null){                                 sb.append(line);                         }                                         } catch (IOException e) {                         toasterror("流文件讀寫錯(cuò)誤");                         e.printStackTrace();                 }finally{                         try {                                 bfr.close();                         } catch (IOException e) {                                 toasterror("流文件未能正常關(guān)閉");                                 e.printStackTrace();                         }                 }                 return sb.toString(); }

downFiletoDecive(String url,String filename)方法下載文件到設(shè)備內(nèi)存,下載的文件在應(yīng)用的路徑file下:

public void downFiletoDecive(String url,String filename){                     if((url!=null&&!"".equals(url))&&(filename!=null&&!"".equals(filename))){                             InputStream input = getinputStream(url);                             FileOutputStream outStream = null;                             try {                                     outStream = c.openFileOutput(filename, Context.MODE_WORLD_READABLE|Context.MODE_WORLD_WRITEABLE);                                     int temp = 0;                                     byte[] data = new byte[1024];                                     while((temp = input.read(data))!=-1){                                             outStream.write(data, 0, temp);                                     }                             } catch (FileNotFoundException e) {                                     toasterror("請(qǐng)傳入正確的上下文");                                     e.printStackTrace();                             } catch (IOException e) {                                     toastemessage("讀寫錯(cuò)誤");                                     e.printStackTrace();                             }finally{                                     try {                                             outStream.flush();                                             outStream.close();                                     } catch (IOException e) {                                             toasterror("流文件未能正常關(guān)閉");                                             e.printStackTrace();                                     }                                                                 }                     }                     toastemessage("下載成功");             }

downFiletoSDCard(String url,String path,String filename)下載文件到SDCard中,自定義保存路:

public void downFiletoSDCard(String url,String path,String filename){                                 if((url!=null&&!"".equals(url))&&(path!=null)&&(filename!=null&&!"".equals(filename))){                                                                 InputStream input = getinputStream(url);                                 downloader(input, path, filename);                                         }else{                                 /*                                  * 對(duì)不合發(fā)的參數(shù)做處理                                  */                                 if(url==null||"".equals(url)){                                         toasterror("url不能為空或?yàn)椤啊?);                                 }                                 if(path==null){                                         toasterror("path不能為空");                                 }                                 if(filename==null||"".equals(filename)){                                         toasterror("filename不能為空");                                 }                 }                         }

關(guān)于Android 中怎么利用Http下載文件到手機(jī)問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。


當(dāng)前題目:Android中怎么利用Http下載文件到手機(jī)
標(biāo)題鏈接:http://weahome.cn/article/gshpgc.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部