zoukankan      html  css  js  c++  java
  • 导出方法(记录)

    //将数据保存到临时文件

    public String wordPrint(File file,HttpServletRequest request, HttpServletResponse response)
    throws IOException {
    InputStream fin = null;
    ServletOutputStream out = null;
    try {
    fin = new FileInputStream(file);

    response.setCharacterEncoding("utf-8");
    response.setContentType("application/msword");
    // 设置浏览器以下载的方式处理该文件名

    response.setHeader("Content-Disposition", "attachment;filename="
    .concat(String.valueOf(URLEncoder.encode(file.getName(), "UTF-8"))));

    out = response.getOutputStream();
    byte[] buffer = new byte[2048]; // 缓冲区
    int bytesToRead = -1;
    // 通过循环将读入的Word文件的内容输出到浏览器中
    while((bytesToRead = fin.read(buffer)) != -1) {
    out.write(buffer, 0, bytesToRead);
    }
    } finally {
    if(fin != null) fin.close();
    if(out != null) out.close();
    if(file != null) file.delete(); // 删除临时文件
    }

    return null;
    }

  • 相关阅读:
    Redux 学习总结
    ECMAScript 6 学习总结
    Bootstrap 前端UI框架
    React.js 学习总结
    html 之 <meta> 标签之http-equiv
    Leetcode Excel Sheet Column Number (C++) && Excel Sheet Column Title ( Python)
    490
    414
    494
    458
  • 原文地址:https://www.cnblogs.com/czgxxwz/p/7683540.html
Copyright © 2011-2022 走看看