從url獲取圖片

          public static File getLogoFromWeb(String logourl, String uploadPath) {
                  try {
                      URL url = new URL(logourl);
                      String fileType = logourl.substring(logourl.lastIndexOf("."), logourl.length());
                      File outFile = new File(uploadPath + UUID.randomUUID().toString().replace("-", "") + fileType);
                      OutputStream os = new FileOutputStream(outFile);
                      InputStream is = url.openStream();
                      byte[] buff = new byte[1024];
                      while (true) {
                          int readed = is.read(buff);
                          if (readed == -1) {
                              break;
                          }
                          byte[] temp = new byte[readed];
                          System.arraycopy(buff, 0, temp, 0, readed);
                          os.write(temp);
                      }
                      is.close();
                      os.close();
                      return outFile;
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
                  return null;
              }

          posted on 2012-10-23 10:10 Mr.lu 閱讀(1433) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2012年10月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 鄂托克旗| 湖南省| 黄陵县| 柳林县| 凤山市| 古丈县| 玛沁县| 平和县| 天门市| 离岛区| 吴旗县| 万全县| 元江| 桃园县| 北宁市| 襄汾县| 葫芦岛市| 成都市| 石台县| 营口市| 灵武市| 汉源县| 方城县| 阿荣旗| 潞西市| 南靖县| 五峰| 商水县| 历史| 新安县| 吉木萨尔县| 剑阁县| 沧州市| 安陆市| 陕西省| 绥德县| 体育| 固阳县| 温州市| 马鞍山市| 若尔盖县|