zoukankan      html  css  js  c++  java
  • 下载服务器上的文件

    @RequestMapping("downLoadExcel")
    public String downLoadExcel(HttpServletRequest request,HttpServletResponse response){
    try {
    //路径
    String path = request.getSession().getServletContext().getRealPath("/template/");
         //下面的两行设置响应头,必须设置,以弹框的形式下载 中文乱码记得要转码啊!!!!!!!!!!!!!
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment;fileName="+new String("指数模板.xlsx".getBytes(),"ISO8859-1"));//
    ServletOutputStream out;
         //File.separator 文件夹的分割线,不同的操作系统之间可以通用
    File file = new File(path+File.separator+ "指数模板.xlsx");
    FileInputStream inputStream = new FileInputStream(file);
    out = response.getOutputStream();
    int len= 0;
    byte[] buffer = new byte[1024];
    while ((len=inputStream.read(buffer))!=-1){
    out.write(buffer,0,len);
    }
    inputStream.close();
    out.close();
    out.flush();
    } catch (Exception e) {
    e.printStackTrace();
    }
    return null;
    }
  • 相关阅读:
    [haoi2015]T1
    [haoi2014]走出金字塔
    [haoi2014]穿越封锁线
    [haoi2014]遥感监测
    [haoi2012]高速公路
    [haoi2012]容易题
    [haoi2008]排名系统
    【bzoj1014】[JSOI2008]火星人prefix
    0916解题报告
    生成树计数问题
  • 原文地址:https://www.cnblogs.com/feixian/p/5960210.html
Copyright © 2011-2022 走看看