springboot根据uRL下载文件到本地
时间: 2023-10-13 19:04:17 浏览: 135
可以使用SpringBoot来实现根据URL下载文件到本地的功能。以下是一个示例代码:
```java
@GetMapping("/download")
public void download(@RequestParam("url") String urlStr, HttpServletResponse response) throws IOException {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
try (InputStream inputStream = conn.getInputStream();
OutputStream outputStream = new FileOutputStream("路径/文件名")) {
byte[] buffer = new byte<span class="em">1</span><span class="em">2</span>
#### 引用[.reference_title]
- *1* [SpringBoot实现通过url下载pdf到本地](https://blog.csdn.net/MCmango/article/details/113937695)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [Vue+SpringBoot根据url返回文件流给前端下载文件(多个图片zip下载)](https://blog.csdn.net/zcl520sy/article/details/130142189)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文