public BufferedImage loadImgByUrl( String imgUrl){ //创建httpClient客户端 CloseableHttpClient httpClient=HttpClients.createDefault(); //创建httpGet发送请求获取文件 HttpGet httpGet=new HttpGet(imgUrl); //将文件读入到输入流中 try(CloseableHttpResponse httpResponse=httpClient.execute(httpGet); InputStream input=httpResponse.getEntity().getContent()){ return ImageIO.read(input); } catch (Exception e) { logger.error("loadImgByUrl加载图片失败"); } return null; }
根据图片URL加载图片到缓存
最新推荐文章于 2023-08-17 19:22:32 发布