博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
通过URL解析下载资源
阅读量:249 次
发布时间:2019-03-01

本文共 807 字,大约阅读时间需要 2 分钟。

package com.tencent.UDP; import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.net.HttpURLConnection;import java.net.URL;public class Download {    public static void main(String[] args) throws IOException {        URL url = new URL("http://m.0714news.com/videos/b4e0ba24a77940aa.mp4");         HttpURLConnection u = (HttpURLConnection)url.openConnection();        InputStream is = u.getInputStream();        FileOutputStream fos = new FileOutputStream("C://Users//mibook//Desktop//jay.mp4");        byte[] buffer = new byte[1024];        int len = 0;        while((len = is.read(buffer)) != -1) {            fos.write(buffer , 0 , buffer.length);            System.out.println(buffer);        }        fos.close();        is.close();        u.disconnect();    }}

 

转载地址:http://sjpt.baihongyu.com/

你可能感兴趣的文章