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

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 岳普湖县| 冀州市| 张掖市| 丹巴县| 高唐县| 揭西县| 平武县| 新蔡县| 曲阜市| 临朐县| 临清市| 泰州市| 天水市| 南宁市| 滕州市| 吕梁市| 台前县| 肃南| 衡阳县| 贡山| 芜湖县| 自治县| 江城| 安徽省| 遵义县| 克什克腾旗| 炉霍县| 海淀区| 九江市| 南溪县| 个旧市| 湾仔区| 九龙城区| 五寨县| 塘沽区| 页游| 灵丘县| 旬阳县| 盐边县| 临安市| 昂仁县|