java 下载文件

贴个轮子

//下载视频方法
    private static void getDondow(String url,String pathName)throws Exception{
        URL ul = new URL(url);
        HttpURLConnection conn = (HttpURLConnection) ul.openConnection();
        BufferedInputStream bi = new BufferedInputStream(conn.getInputStream());
        FileOutputStream bs = new FileOutputStream(pathName);
        System.out.println("文件大约:"+(conn.getContentLength()/1024)+"K");
        byte[] by = new byte[1024];
        int len = 0;
        while((len=bi.read(by))!=-1){
            bs.write(by,0,len);
        }
        bs.close();
        bi.close();
    }
原文地址:https://www.cnblogs.com/opensesame/p/6410774.html