File download with android

人走茶凉 提交于 2019-12-02 06:12:35

I solved it!

           File card2= Environment.getExternalStorageDirectory();
           File dir2= new File (card2.getAbsolutePath()+"/MyFiles");
            dir2.mkdirs();
           new DefaultHttpClient().execute(new HttpGet(your_url_here-this_is_a_string)).getEntity().writeTo(
            new FileOutputStream(new File(dir2,your_file_on_sdcard-this_is_string)));

This is also surrounded by try/catch. And remember to insert the protocol before the address or it won't work! Hope it helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!