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

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 甘洛县| 宝丰县| 遵化市| 芜湖县| 嘉善县| 罗平县| 喀喇沁旗| 合山市| 遵化市| 高平市| 清新县| 阳山县| 石阡县| 阿克陶县| 滁州市| 泰和县| 克山县| 桓台县| 额济纳旗| 大连市| 林甸县| 仪征市| 阿巴嘎旗| 白水县| 桐梓县| 抚州市| 泽库县| 洞口县| 抚顺县| 章丘市| 文山县| 徐州市| 辉县市| 洛南县| 新竹市| 治县。| 贞丰县| 高陵县| 个旧市| 湾仔区| 大荔县|