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

  • 相关阅读:
    触摸事件传递与响应者链条
    运动事件Motion Events
    手势识别
    MVC模式
    单例模式
    观察者模式(一对多)
    关于多线程的介绍
    Sandbox简介和路径获取
    NSFileManager和NSFileHandle使用
    归档储存
  • 原文地址:https://www.cnblogs.com/czgxxwz/p/7683540.html
Copyright © 2011-2022 走看看