一,注意path地址是http请求访问到的地址,而不是文件路径

//后台代码

response.setHeader("Content-Disposition", "attachment;filename="+filename);

URL url = new URL(path);
// path是指欲下载的文件的路径。
URLConnection conn = url.openConnection();
InputStream fis = conn.getInputStream();
OutputStream out = response.getOutputStream();
//写文件
int b;
while((b=fis.read())!= -1){
out.write(b);
}
fis.close();
out.close();

这是浏览器直接下载

 

第二种,前端js方式

window.open('https://1.1.1.1/test.txt')

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2021-11-23
  • 2022-12-23
  • 2021-12-14
  • 2022-12-23
  • 2021-12-06
猜你喜欢
  • 2021-10-16
  • 2021-07-14
  • 2021-05-28
  • 2022-12-23
  • 2021-06-28
  • 2021-12-28
  • 2021-11-18
相关资源
相似解决方案