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

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 宁蒗| 金湖县| 营口市| 淮阳县| 淅川县| 宁波市| 白银市| 沂源县| 泾阳县| 甘谷县| 高碑店市| 如东县| 开封市| 昌图县| 天气| 嘉义县| 兴和县| 同江市| 定西市| 息烽县| 江永县| 东乌珠穆沁旗| 那曲县| 汉中市| 霍邱县| 永清县| 台中市| 潜江市| 徐州市| 阳东县| 拜城县| 固始县| 乐业县| 岢岚县| 宁海县| 民县| 永修县| 沅江市| 沈丘县| 孝昌县| 衡山县|