-1
String fileName="raj.doc";
ServletOutputStream stream=null;
BufferedInputStream buf=null;
stream=res.getOutputStream();
String s1=getServletContext().getRealPath("/web-inf/lib/raj.doc");
File doc=new File(s1);
res.setContentType("application/vnd.ms-word");
res.addHeader("Content-Disposition","attachment;filename= "+fileName);
res.setContentLength((int)doc.length());
FileInputStream input=new FileInputStream(doc);
buf=new BufferedInputStream(input);
int readBytes=0;
while((readBytes=buf.read())!=-1)
stream.write(readBytes);
给我一个在java中下载MS-word文件的例子。告诉我需要的jar文件。如何在java下载MS-word文件?
你想*从服务器上下载*文件,或者*阅读*你已有的文件?如果是后者,请查看[Apache Poi](https://poi.apache.org/)。 –
我有预定义的模板。我想以MS-word类型下载该模板。 –