大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節(jié)點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 hot資訊 Java視頻下載的方法

Java視頻下載的方法

更新時間:2021-04-27 11:41:02 來源:動力節(jié)點 瀏覽1010次

方法一


package com.amigo.online.provider.manager.util.video.download;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class VideoDownload {
	public static boolean httpDownload(String httpUrl, String saveFile) {
        // 1.下載網(wǎng)絡(luò)文件
        int byteRead;
        URL url;
        try {
            url = new URL(httpUrl);
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
            return false;
        }
 
        try {
            //2.獲取鏈接
            URLConnection conn = url.openConnection();
            //3.輸入流
            InputStream inStream = conn.getInputStream();
            //3.寫入文件
            FileOutputStream fs = new FileOutputStream(saveFile);
 
            byte[] buffer = new byte[1024];
            while ((byteRead = inStream.read(buffer)) != -1) {
                fs.write(buffer, 0, byteRead);
            }
            inStream.close();
            fs.close();
            return true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
	
	public static void main(String[] args) {
		System.out.println(httpDownload("http://yun.it7090.com/video/XHLaunchAd/video01.mp4","D:\\image\\22.mp4"));
	}
}

方法二


package com.amigo.online.provider.manager.util.video.download;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import org.jboss.logging.Logger;
public class VideoDownloadUtil {
	private static final Logger LOGGER = Logger.getLogger(VideoDownloadUtil.class);
	/**
     * 下載文件到本地
     *
     * @param urlString
     *          被下載的文件地址
     * @param filename
     *          本地文件名
     * @param timeout
     *          超時時間毫秒
     * @throws Exception
     *           各種異常
     */
   
	 @SuppressWarnings("finally")
	public static boolean download(String urlString, String filename,int timeout){
	        boolean ret = false;
	        File file = new File(filename);
	        try {
	            if(file.exists()){
	                ret = true;
	            }else{
	                // 構(gòu)造URL
	                URL url = new URL(urlString);
	                // 打開連接
	                HttpURLConnection con = (HttpURLConnection )url.openConnection();
	                con.setConnectTimeout(timeout);
	                con.setReadTimeout(timeout);
	                con.connect();
	                int contentLength = con.getContentLength();
	                // 輸入流
	                InputStream is = con.getInputStream();
	                // 1K的數(shù)據(jù)緩沖
	                byte[] bs = new byte[1024];
	                // 讀取到的數(shù)據(jù)長度
	                int len;
	                // 輸出的文件流
 
	                File file2=new File(file.getParent());
	                file2.mkdirs();
	                if(file.isDirectory()){
 
	                }else{
	                    file.createNewFile();//創(chuàng)建文件
	                }
	                OutputStream os = new FileOutputStream(file);
	                // 開始讀取
	                while ((len = is.read(bs)) != -1) {
	                    os.write(bs, 0, len);
	                }
	                // 完畢,關(guān)閉所有鏈接
	                os.close();
	                is.close();
	                if(contentLength != file.length()){
	                    file.delete();
	                    ret = false;
	                }else{
	                    ret = true;
	                }
	            }
	        } catch (IOException e) {
	            file.delete();
	            ret = false;
	            LOGGER.error("[VideoUtil:download]:\n" + " VIDEO URL:" + urlString + " \n NEW FILENAME:" + filename + " DOWNLOAD FAILED!! ");
	        }finally {
	            return ret;
	        }
	    }
    public static void main(String[] args) {
    	System.out.println(download("http://yun.it7090.com/video/XHLaunchAd/video01.mp4","D:\\image\\969.mp4",1000000000));
	}
  }  

以上就是動力節(jié)點小編介紹的“Java視頻下載的方法”的內(nèi)容,希望對大家有幫助,如有疑問,請在線咨詢,有專業(yè)老師隨時為您服務(wù)。

提交申請后,顧問老師會電話與您溝通安排學(xué)習(xí)

免費課程推薦 >>
技術(shù)文檔推薦 >>
主站蜘蛛池模板: 五月天亚洲婷婷 | 亚洲精品一二三 | 欧美色v| 在线播放国产区 | 精品视频www| 四虎8848 | 精品图区 | 精品久久久久中文字幕日本 | 日本三级11k影院在线 | 精品一久久香蕉国产线看观看下 | 日韩欧美理论 | 日日摸夜夜摸狠狠摸日日碰夜夜做 | 国产精品揄拍一区二区久久 | 亚洲欧美综合精品成 | 这里是九九伊人 | 噜噜噜天天躁狠狠躁夜夜精品 | 亚洲综合图片网 | 欧美日韩亚洲国产无线码 | 色国产精品 | 日韩在线一| 99精品免费久久久久久久久日本 | 日日人人| 999热精品这里在线观看 | 外国一级黄色毛片 | 97人人在线视频 | 亚洲欧美另类精品久久久 | 国产一区亚洲一区 | 久久999精品 | 国产成人午夜性a一级毛片 国产成人午夜性视频影院 国产成人系列 | 亚洲国产福利精品一区二区 | 久久综合给合久久狠狠狠97色 | 久久91精品综合国产首页 | 欧美一级毛片香蕉网 | 色偷偷青青草原在线视频 | 久久中文字幕视频 | 欧美在线香蕉在线现视频 | 久久99网 | 香蕉视频国产在线观看 | 国产亚洲欧洲国产综合一区 | 欧美在线不卡 | 国产中文字幕视频在线观看 |