zoukankan      html  css  js  c++  java
  • Android为TV端助力 http下载视频到指定目录

    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();
    }
    }
    }

    }
  • 相关阅读:
    黄金作为货币的本质
    万有引力和做功。
    Arp攻击实战
    Android SDK下载项的说明
    宇宙、事象
    事件视界
    微积分
    金融的三大基础货币,股票,期货。
    pos机的热敏纸尺寸
    去除text历史记录
  • 原文地址:https://www.cnblogs.com/xiaoxiaing/p/6442235.html
Copyright © 2011-2022 走看看