zoukankan      html  css  js  c++  java
  • 点击按钮下载文件

     
    @RequestMapping("/download.do")
        public void download(HttpServletRequest request,
                HttpServletResponse response)
                throws Exception {
            String filePath = "文件路径";
            FileInputStream fis = null;
            OutputStream os = null;
            try {
                fis = new FileInputStream(filePath);
                os = response.getOutputStream();// 取得输出流
                response.reset();// 清空输出流
                response.setHeader("Content-disposition", "attachment; filename="
                        + filePath.substring(filePath.lastIndexOf("/") + 1));// 设定输出文件头
                response.setContentType("application/x-download");
                byte[] mybyte = new byte[8192];
                int len = 0;
                while ((len = fis.read(mybyte)) != -1) {
                    os.write(mybyte, 0, len);
                }
                os.close();
            } catch (IOException e) {
                throw e;
            }
        }
  • 相关阅读:
    Linux命令:ssh
    Linux命令:sshpass
    Linux命令:ls
    Linux文件的时间
    Linux命令:findutils
    jfrog
    git
    git branch
    git remote
    java equals 和hashcode
  • 原文地址:https://www.cnblogs.com/dashuai01/p/4773183.html
Copyright © 2011-2022 走看看