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

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

你可能感兴趣的:(exception,url,存储,手机,byte)