使用HttpURLConnection如何下载提示啊,下边是我的代码

 public  boolean saveUrlAs(String photoUrl, String fileName)
      {
              try
              {
                      URL url = new URL(photoUrl);
                      HttpURLConnection connection = (HttpURLConnection)url.openConnection();
                      DataInputStream in = new DataInputStream(connection.getInputStream());
                      DataOutputStream out = new DataOutputStream(new FileOutputStream(fileName));
                      byte buffer[] = new byte[5120];
                      for (int count = 0; (count = in.read(buffer)) > 0;)
                              out.write(buffer, 0, count);
                      out.close();
                      in.close();
                      //connection.disconnect();
              }
              catch (Exception e)
              {
                      e.printStackTrace();
                      return false;
              }
              return true;
      }

猜你喜欢

转载自201403051219.iteye.com/blog/2029836