游戏技术文章

android http下载视频到指定目录

时间:2017-2-26 12:00:54  作者:棋牌资源网  来源:棋牌资源网  查看:7802  评论:0
内容摘要:public void httpget(String uri){ HttpURLConnection connection = null; FileOutputStream fos = null; File fie = new File("/sdcar...
public void httpget(String uri){
    HttpURLConnection connection = null;
    FileOutputStream fos = null;
    File fie = new File("/sdcard/W_Local_Data/LiveVideo_file/");
    if(!fie.exists()){
        fie.mkdirs();
    }
    File ff = new File(fie.toString(),"abcd.mp4");
    if(!ff.exists()&&ff.isFile()){
        try {
            ff.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    try {
        URL u = new URL(uri);
        connection = (HttpURLConnection)u.openConnection();
        connection.setConnectTimeout(3000);
        connection.setRequestProperty("Charset", "UTF-8");
        if(connection.getResponseCode() == 200){
            InputStream is = connection.getInputStream();

            byte buf[] = new byte[1024];
            int ii  ;
            fos = new FileOutputStream(ff);
            while ((ii = is.read(buf))!=-1){
                fos.write(buf,0,ii);
            }
            fos.flush();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }finally {
        if(connection != null){
            connection.disconnect();
        }
        if(fos != null){
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
标签:androidhttp下载视频到指定目录 

欢迎加入VIP,【VIP售价:只要288元永久VIP会员】畅享商业棋牌游戏程序下载,点击开通!

下载说明


☉本站所有源码和资源均由站长亲自测试-绝对保证都可以架设,运营!
☉如源码和资源有损坏或所有链接均不能下载,请告知管理员,

☉本站软件和源码大部分为站长独资,资源购买和收集,放心下载!

☉唯一站长QQ:1004003180  [人格担保-本站注重诚信!]

☉购买建议E-mail:1004003180@qq.com   源码收购 E-mail:1004003180@qq.com    

☉本站文件解压密码  【文章内都自带解压密码,每个密码不同!】


本站提供的所有源码,均来源站长提供,仅学习交流 浙ICP备09009969号

由此产生不良后果和法律责任与本站无关,如果侵犯了您的版权,请来信告知 1004003180@qq.com 将及时更正和删除! 

Copyright © 2008-2024 棋牌资源网,你身边的棋牌资源下载站    All Rights Reserved