java实现文件下载两种方式(一)

java实现文件下载两种方式(一)

前端直接超链接即可,修改文件类型需修改contenttype中的类型

 public void export(HttpServletResponse response) throws IOException {
       File f=new File("文件路径");
       response.reset();
       response.setContentType("application/octet-stream;charset=utf-8");
       response.setHeader("Content-Disposition","attachment; filename="+System.currentTimeMillis()+".txt");
       OutputStream out=response.getOutputStream();
       workbook.write(out);
       out.flush();
       out.close();
   }`
发布了5 篇原创文章 · 获赞 0 · 访问量 97

猜你喜欢

转载自blog.csdn.net/a734475064/article/details/105285238