從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 閱讀(1429) 評論(0)  編輯  收藏


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


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

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 宜城市| 彰化县| 北安市| 绥芬河市| 体育| 徐汇区| 汝州市| 曲阜市| 澄城县| 榕江县| 宜章县| 咸丰县| 垦利县| 濉溪县| 伊川县| 东辽县| 漾濞| 襄城县| 阿合奇县| 孝义市| 壤塘县| 铁力市| 银川市| 蚌埠市| 岳池县| 萨嘎县| 浦东新区| 昭觉县| 浪卡子县| 宿松县| 许昌县| 桂东县| 柳江县| 云梦县| 宜城市| 延寿县| 大庆市| 山阳县| 雅安市| 滨海县| 保德县|