• java 文件下载支持中文名称


      /**
         * 文件下载
         * @param filePath  文件路径
         * @param fileName  文件名称
         */
        public void download(String filePath,String fileName){
            try {
           //支持中文
                fileName = URLEncoder.encode(fileName,"UTF-8");
                HttpServletResponse response = ServletActionContext.getResponse();
                HttpServletRequest request = ServletActionContext.getRequest();
                response.reset();
                response.setContentType(request.getServletContext().getMimeType(fileName));  
                response.setHeader("Content-Disposition", "attachment;filename="+fileName); 
                InputStream in = new FileInputStream(filePath);  
                OutputStream out = response.getOutputStream();  
                  
                byte[] b = new byte[1024];
                int length = 0;
                while((length = in.read(b)) != -1)  {  
                    out.write(b,0,length);  
                }  
                in.close();  
                out.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
  • 相关阅读:
    格式与布局 float 左右悬浮边框
    格式与布局
    样式表
    c# 验证码
    邮箱登录页面
    表单与框架
    HTML 练习 做简历表
    HTML 基础
    验证码 随机数
    Linux 三剑客 -- awk sed grep
  • 原文地址:https://www.cnblogs.com/henuyuxiang/p/11609041.html
Copyright © 2020-2023  润新知