注意:所有文章除特别说明外,转载请注明出处.
概念
这个工具的目的在于下载.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();
}
}