要下载服务器上的文件,可以使用Spring Boot中的`RestTemplate`类来发送HTTP GET请求并获取文件内容。以下是一个示例代码:
```java
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.client.RestTemplate;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
public class FileDownloader {
public static void main(String[] args) throws IOException {
String fileUrl = "http://example.com/file.pdf";
String savePath = "/path/to/save/file.pdf";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(MediaType.APPLICATION_OCTET_STREAM);
RequestEntity