下载文件存入手机内部存储器相应应用文件夹下

来源:互联网 发布:杰森-塔图姆 数据 编辑:程序博客网 时间:2024/04/29 23:09
try
    {
//    InputStream inputStream = null;
//     URL url = new URL("http://download.dams.bigpond.com/drm1/Prod/Online_arts/100/313/067/100313067/Warner_Large_075679963611.jpg");
//     HttpURLConnection conn = (HttpURLConnection) url
//       .openConnection();
//     conn.setConnectTimeout(60*1000);
//     conn.setDoInput(true);
//     conn.connect();  
//     inputStream = conn.getInputStream();
//     int length = (int) conn.getContentLength();
//     //获取文件的大小
//     if (length != -1) {
//      byte[] imgData = new byte[length];
//      byte[] temp = new byte[512];
//      int readLen = 0;
//      int destPos = 0;
//      while ((readLen = inputStream.read(temp)) > 0) {
//       System.arraycopy(temp, 0, imgData, destPos, readLen);
//       destPos += readLen;
//      }
     
     FileOutputStream fos = openFileOutput("img.jpg", Context.MODE_PRIVATE);
     fos.write(imgData);
     fos.close();
//    }
    }
    
    catch (Exception e)
    {
     e.printStackTrace();
    }
   
原创粉丝点击