使用servlet输出word文档

来源:互联网 发布:腾讯云域名申请后解析 编辑:程序博客网 时间:2024/09/21 09:26
try {
            resp.setContentType(
"application/msword");
            //resp.setHeader(
"Content-disposition","attachment;filename=Example.doc"); //下载用
            File f0 
= new File("c:/example.doc");
            
byte[] b0 = Byte_File_Object.getBytesFromFile(f0);
            BufferedOutputStream  dataOut 
= new BufferedOutputStream(resp.getOutputStream());  
            dataOut.write(b0,
0,b0.length); 
            
if (dataOut!=null) {
                dataOut.close();
            }
        } 
catch (Exception e) {
            e.printStackTrace();
        }