從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)

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 景德镇市| 阳春市| 余干县| 遂平县| 黄平县| 舞钢市| 新蔡县| 西青区| 广州市| 安新县| 南部县| 连南| 衡阳市| 甘德县| 吕梁市| 大名县| 交城县| 普兰县| 沅陵县| 绵阳市| 洛宁县| 农安县| 黑水县| 五指山市| 余姚市| 长岛县| 肥乡县| 湖南省| 德惠市| 南澳县| 陇西县| 茂名市| 无极县| 自治县| 新密市| 裕民县| 建宁县| 大理市| 石河子市| 卢龙县| 铜山县|