1 | /**<br> *文件上传<br> */ |
1 @RequestMapping(value = { "download" }) 2 @ResponseBody 3 public void download( 4 HttpServletResponse response, HttpServletRequest request) throws IOException { 5 String path=request.getServletContext().getRealPath("/")+"WEB-INF/download/erep/"; 6 String fileName="模板.xls"; 7 File file1=new File(path,fileName); 8 response.setCharacterEncoding("UTF-8"); 9 //response.setContentType("application/x-msdownload"); 10 //response.setContentType("application/octet-stream; charset=utf-8"); 11 response.setHeader("Content-Disposition", "attachment; filename="+new String(fileName.getBytes("gbk"),"iso-8859-1")); 12 response.setHeader("Content-Length", String.valueOf(file1.length())); 13 ServletOutputStream out = response.getOutputStream(); 14 byte[] array = FileUtils.readFileToByteArray(file1); 15 out.write(array); 16 out.flush(); 17 out.close(); 18 19 20 }
1 2 3 4 5 6 7 8 9 | /**<br> *文件上传<br> */ <br> @RequestMapping (value = { "upload" }) @ResponseBody public void upload( @RequestParam ( "file" ) MultipartFile file, HttpServletResponse response, HttpServletRequest request) throws IOException { String name = file.getOriginalFilename(); String filename=UUID.randomUUID().toString()+name; String path=request.getServletContext().getRealPath( "/" )+ "WEB-INF/download/erep/" ; FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path+filename)); } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步