JAVA通过URL保存远程图片

刚用到的,保留在此,以备查询。
try {
      URL url = new URL(
          "http://lh3.ggpht.com/_d4XrOKBCIPc/ScL_LIHMDAI/AAAAAAAAABI/mP8Dmd0h9XY/s72/error.png");
      java.io.BufferedInputStream bis = new BufferedInputStream(url.openStream());
      byte[] bytes = new byte[100];
      OutputStream bos = new FileOutputStream(new File("C:\\index_logo.gif"));
      int len;
      while ( (len = bis.read(bytes)) > 0) {
        bos.write(bytes, 0, len);
      }
      bis.close();
      bos.flush();
      bos.close();

    }
    catch (Exception e) {
      e.printStackTrace();
    }

你可能感兴趣的:(java,C++,c,C#)