您好,欢迎来到99网。
搜索
您的当前位置:首页java附件,文档下载

java附件,文档下载

来源:99网
	@RequestMapping("/createReporNewWord")
    @ResponseBody
    public ResponseEntity<byte[]> createReporNewWord(RfgcMaintenanceEvaluationReport model, HttpSession session){
    	//创建附件(自己的业务)
        //File excelFile = getRfgcMaintenanceevaluationreportService().getExportWord(model);
        // 获取桌面路径
        FileSystemView fsv = FileSystemView.getFileSystemView();
        File path=fsv.getHomeDirectory();
        File excelFile = File.createTempFile(System.currentTimeMillis(), ".txt", path);
        if(excelFile == null){
            return null;
        }
        ResponseEntity<byte[]> result = null;
        try {
            HttpHeaders headers = new HttpHeaders();
            String agent = (String)getRequest().getHeader("USER-AGENT");
            if(agent != null && agent.toLowerCase().indexOf("firefox") > 0){
                headers.setContentDispositionFormData("fileName", "=?UTF-8?B?" + (new String(Base.encodeBase(excelFile.getName().getBytes("UTF-8")))) + "?=");
            }else{
                headers.setContentDispositionFormData("fileName", URLEncoder.encode(  excelFile.getName(),"UTF-8"));
            }
            headers.setContentType(MediaType.MULTIPART_FORM_DATA);
            result = new ResponseEntity<byte[]>(FileUtil.readAsByteArray(excelFile), headers, HttpStatus.OK);

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //删除文件
            File finalExcelFile = excelFile;
            new Thread(() -> {
                try {
                    Thread.sleep(30000);
                    if (finalExcelFile.exists()){
                        finalExcelFile.delete();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
        }
        return result;
    }

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 99spj.com 版权所有 湘ICP备2022005869号-5

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务