zoukankan      html  css  js  c++  java
  • java 文件下载

    后台:

    /** *

     * @param fileId
    * @param request
    * @param response
    */
    @RequestMapping(value = "/downFile", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public void downFile(@RequestParam String fileId,HttpServletRequest request, HttpServletResponse response) {

      //查询文件实体信息
    // Map<String,String> map = jxhFileSerevice.queryFileById(fileId);

    String path = "E:file新框架文件.docx";
    File file = new File(path);
    String fileName = "新框架文件.docx";
    if (!file.exists()) {
    System.out.println("没有找到: " + path);
    return;
    }
    try {
    String head = new String(fileName.getBytes(), "iso-8859-1");
    response.setHeader("Content-Disposition", "attachment;filename=" + head);
    //输入流:本地文件路径
    FileInputStream in = new FileInputStream(file);
    //输出流
    OutputStream out = response.getOutputStream();
    //输出文件
    int bytes = 0;
    byte[] bufferOut = new byte[1024];
    while ((bytes = in.read(bufferOut)) != -1) {
    out.write(bufferOut, 0, bytes);
    }
    out.close();
    in.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }


    前端js
    /** 下载文件 */
    function dowmloadFile(fileId){
    window.location.href='jxh/inner/serApiApply/downFile?fileId='+fileId;
    //window.location.href ="/visits/dowLoadFileToPC?fileId="+obj;
    }





  • 相关阅读:
    面向对象程序设计寒假作业2
    面向对象程序设计寒假作业1
    自我介绍
    3组-Alpha冲刺-1/6
    3组 需求分析报告
    3组 团队展示
    第一次个人编程作业
    第一次博客作业
    我罗斯方块最终篇
    我罗斯方块设计
  • 原文地址:https://www.cnblogs.com/superming/p/11599250.html
Copyright © 2011-2022 走看看