免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
java 從網(wǎng)絡(luò)Url中下載文件
  1. /** 
  2.      * 從網(wǎng)絡(luò)Url中下載文件 
  3.      * @param urlStr 
  4.      * @param fileName 
  5.      * @param savePath 
  6.      * @throws IOException 
  7.      */  
  8.     public static void  downLoadFromUrl(String urlStr,String fileName,String savePath) throws IOException{  
  9.         URL url = new URL(urlStr);    
  10.         HttpURLConnection conn = (HttpURLConnection)url.openConnection();    
  11.                 //設(shè)置超時間為3秒  
  12.         conn.setConnectTimeout(3*1000);  
  13.         //防止屏蔽程序抓取而返回403錯誤  
  14.         conn.setRequestProperty("User-Agent""Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");  
  15.   
  16.         //得到輸入流  
  17.         InputStream inputStream = conn.getInputStream();    
  18.         //獲取自己數(shù)組  
  19.         byte[] getData = readInputStream(inputStream);      
  20.   
  21.         //文件保存位置  
  22.         File saveDir = new File(savePath);  
  23.         if(!saveDir.exists()){  
  24.             saveDir.mkdir();  
  25.         }  
  26.         File file = new File(saveDir+File.separator+fileName);      
  27.         FileOutputStream fos = new FileOutputStream(file);       
  28.         fos.write(getData);   
  29.         if(fos!=null){  
  30.             fos.close();    
  31.         }  
  32.         if(inputStream!=null){  
  33.             inputStream.close();  
  34.         }  
  35.   
  36.   
  37.         System.out.println("info:"+url+" download success");   
  38.   
  39.     }  
  40.   
  41.   
  42.   
  43.     /** 
  44.      * 從輸入流中獲取字節(jié)數(shù)組 
  45.      * @param inputStream 
  46.      * @return 
  47.      * @throws IOException 
  48.      */  
  49.     public static  byte[] readInputStream(InputStream inputStream) throws IOException {    
  50.         byte[] buffer = new byte[1024];    
  51.         int len = 0;    
  52.         ByteArrayOutputStream bos = new ByteArrayOutputStream();    
  53.         while((len = inputStream.read(buffer)) != -1) {    
  54.             bos.write(buffer, 0, len);    
  55.         }    
  56.         bos.close();    
  57.         return bos.toByteArray();    
  58.     }    
  59.   
  60.     public static void main(String[] args) {  
  61.         try{  
  62.             downLoadFromUrl("http://101.95.48.97:8005/res/upload/interface/apptutorials/manualstypeico/6f83ce8f-0da5-49b3-bac8-fd5fc67d2725.png",  
  63.                     "百度.jpg","d:/resource/images/diaodiao/country/");  
  64.         }catch (Exception e) {  
  65.             // TODO: handle exception  
  66.         }  
  67.     }  

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
jfreechart圖片直接轉(zhuǎn)為byte[]然后轉(zhuǎn)為base64導(dǎo)入xml,最后圖片導(dǎo)入word
(原)用java流方式判斷文件類型
基于SMB/JCIFS協(xié)議的共享文件上傳和下載
HttpURLConnection(訪問網(wǎng)絡(luò))
文件上傳流式處理commons
將輸出流(OutputStream)轉(zhuǎn)化為輸入流(InputStream)的方法(一)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服