Fork me on GitHub

word - util

注意:所有文章除特别说明外,转载请注明出处.

概念

这个工具的目的在于下载.doc文档

package cn.edu.xidian.see.util;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.InputStream;

/**
 * Windows Word
 * Created by llq on 2017/2/21.
 */
public class WordUtil {

    public static void download(HttpServletResponse response, InputStream in,
                                String downloadFileName) throws Exception {
        BufferedInputStream bis;
        BufferedOutputStream bos;

        response.reset();
        response.setContentType("application/msword;charset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename="
                + new String((downloadFileName + ".doc").getBytes(), "iso-8859-1"));
        ServletOutputStream out = response.getOutputStream();

        bis = new BufferedInputStream(in);
        bos = new BufferedOutputStream(out);
        byte[] buff = new byte[1024];
        int readlen = 0;
        while ((readlen = bis.read(buff, 0, buff.length)) != -1) {
            bos.write(buff, 0, readlen);
        }

        bis.close();
        bos.close();
    }

}

本文标题:word - util

文章作者:Bangjin-Hu

发布时间:2019年10月15日 - 09:22:26

最后更新:2020年03月30日 - 07:57:28

原始链接:http://bangjinhu.github.io/undefined/WordUtil/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

Bangjin-Hu wechat
欢迎扫码关注微信公众号,订阅我的微信公众号.
坚持原创技术分享,您的支持是我创作的动力.