String url = "https://img3.doubanio.com/view/status/l/public/103861781-665301078817f01.jpg";
//创建restTemplate对象
org.springframework.web.client.RestTemplate restTemplate = new org.springframework.web.client.RestTemplate();
/**
* 请求地址
* 请求方式
* 请求实体类
* 请求返回类型
*/
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, byte[].class);
//获取entity中的数据
byte[] body = responseEntity.getBody();
//创建输出流 输出到本地
FileOutputStream fileOutputStream = new FileOutputStream(new File("F:\\fuwuqi\\1.jpg"));
fileOutputStream.write(body);
//关闭流
fileOutputStream.close();
RestTemplate下载图片
最新推荐文章于 2024-06-12 08:49:41 发布