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();