//初始化private file vIDeofile;private voID init(){ String root = Environment.getExternalStorageDirectory().toString(); vIDeofile = new file(root + file.separator + "jbrVIDeo"); if (!vIDeofile.exists()|| !vIDeofile.isDirectory()){ vIDeofile.mkdirs(); }}//下载视频public voID saveVIDeoTofile(final List<String> List){ new Thread(){ @OverrIDe public voID run() { for (int i = 0; i < List.size(); i++) { try { URL url = new URL(List.get(i)); inputStream is = url.openStream(); writeOs(is,i); } catch (MalformedURLException e) { } catch (IOException e) { } } } }.start();}
//将视频保存到本地private voID writeOs(inputStream is, int position){ OutputStream os = null; try { file file = new file(vIDeofile.getabsolutePath(), "vIDeo" + position + ".mp4"); TipUtil.log("file : " + file.toString()); os = new fileOutputStream(file); byte buf[] = new byte[2*1024]; int read = 0; while ((read = is.read(buf)) != -1){ os.write(buf,0,read); } os.flush(); os.close(); is.close(); } catch (fileNotFoundException e) { } catch (IOException e) { }}
//获取视频地址public file[] getVIDeofiles(){ return vIDeofile.Listfiles();}总结
以上是内存溢出为你收集整理的Android 下载mp4到File全部内容,希望文章能够帮你解决Android 下载mp4到File所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)