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;
    }

  • 相关阅读:
    linux 内核配置
    使用 git 下载linux 源码
    订阅 linux 邮件列表注意的问题
    使用反射创建一维数组和二维数组
    反射API
    反射机制
    集合案例--对ArrayList容器中的内容进行排序
    Collections
    TreeSet
    Set容器
  • 原文地址:https://www.cnblogs.com/czgxxwz/p/7683540.html
Copyright © 2011-2022 走看看